DES-Java 프로 그래 밍:DES 암호 화/복호화 사용

DES 는 대칭 암호 화 방법 으로 ECB 암호 화 범례 1 을 보 여 줍 니 다.
try
{
    //   key
    String password = "12345678";
    byte[] b = password.getBytes();
    

    DESKeySpec dks = new DESKeySpec(b);
    
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance( "DES" );
    SecretKey key = keyFactory.generateSecret( dks );
    
    //   cipher
    Cipher cipher = Cipher.getInstance("DES");
    cipher.init(Cipher.ENCRYPT_MODE, key);
    
    //   ,  DES      update( ),   doFinal( )
    String plain = "shaofa00";
    byte [] input = plain.getBytes();
    byte [] output = cipher.update(plain.getBytes());
    
}
catch(Exception e)
{
    
}

범례 2(추천)
try
{
    String password = "12345678";
    byte[] b = password.getBytes();            
    
    SecretKeySpec ks = new SecretKeySpec(b, "DES");
    
    Cipher cipher = Cipher.getInstance("DES");
    cipher.init(Cipher.ENCRYPT_MODE, ks);
    
    String plain = "shaofa00";
    byte [] input = plain.getBytes();
    byte [] output = cipher.update(plain.getBytes());
    
    System.out.println("haha");
}
catch(Exception e)
{
    
}

좋은 웹페이지 즐겨찾기