암호화 알고리즘

(3-DES) 간단한 대칭 알고리즘 예제

긋대디 2018. 12. 26. 22:36

대칭암호화 알고리즘의 종류
    DES & TripleDES : DES(Data Encryption Standard)는 "Lucifer"라는 이름의 IBM에서 최초개발되었다.
    또한 미국에서 최초 국가표준이 되었으며, 56비트키를 가지고 암복호화를 사용했다. 하지만
    컴퓨터가 발전을 함에 있어서 56비트키의 경우 어느정도의 시간만 확보가 된다면 풀어낼수 있기
    때문에 좀더 완벽한 보안을 위하여 Triple DES가 고안
    
    TripleDES : 이는 기존의 DES암호화 알고리즘방식을 다른키에 세번 적용시킨것이며, 첫번째
    암호화과정, 두번째 복호화과정, 세번째는 또 다른 암호화 과정을 거치도록 하고 있다.
    그래서 이름이 DESede(DES encryption, decryption, encryption)이 되었으며, 각각의 과정에 따라
    56비트의 배수로 암호화 복잡도가 증가
    
    Blowfish : 1993년 Bruce Schneier에 의해 고안된 블록암호로서 DES보다 빠르고 안전한 기법을
    제공한다. 
    
    RC4 : "Civest's Code 4"를 의미하며 1987년 RSA Data Security에서 발표되었다. 보통 이기법으로
    TCP/IP연결을 안전하게 하는 SSL을 구현하는 데

 많이 쓰인다(키의 길이 40비트 또는 128비트)





import java.security.*;
import javax.crypto.*;public class SimpleEx1
{
 public static void main (String[] args) throws Exception
 {
  if (args.length != 1) 
  {
   System.err.println("Usage: java SimpleExample text");
   System.exit(1);
  }
  String text = args[0];
  System.out.println("Generating a TripleDES key...");
  // 키생성
  KeyGenerator keyGenerator = KeyGenerator.getInstance("TripleDES");  //알고리즘 선택 TripleDES
  keyGenerator.init(168); // 키 사이즈
  Key key = keyGenerator.generateKey(); // 키 생성
  System.out.println("Done generating the key.");
  // 암호문 객체에 암호 알고리즘 모드 패팅 입력
  Cipher cipher = Cipher.getInstance("TripleDES/ECB/PKCS5Padding");
  cipher.init(Cipher.ENCRYPT_MODE, key);  // 인트립트 모드로 초기화
  byte[] plaintext = text.getBytes("UTF8"); //평문 입력

  System.out.println("\nPlaintext: ");
  for (int i=0;i<plaintext.length;i++) 
  {
   System.out.print(plaintext[i]+" ");
  }
  // 암호화 과정 수행
  byte[] ciphertext = cipher.doFinal(plaintext);
   // 암호문 출력
  System.out.println("\n\nCiphertext: ");
  for (int i=0;i<ciphertext.length;i++) 
  {
   System.out.print(ciphertext[i]+" ");
  }
  // 복호화 모드
  cipher.init(Cipher.DECRYPT_MODE, key);
  // 복호화 수행
  byte[] decryptedText = cipher.doFinal(ciphertext);
  String output = new String(decryptedText,"UTF8");
  System.out.println("\n\nDecrypted text: "+output);
 }
}



 
 
DES 시 수정할 부분 : 
KeyGenerator keyGenerator = KeyGenerator.getInstance("DESede"); 
Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");



'암호화 알고리즘' 카테고리의 다른 글

암호화 역사  (0) 2018.12.27
쉽게보는 ARIA 알고리즘 - 라운드  (0) 2018.12.26
DES 알고리즘 C  (0) 2018.12.26
SHA1withRSA, SHA1withDSA 완성  (0) 2018.12.26
DB암호화 방식 비교  (0) 2018.12.26