RSA 9 1977 RSA Shamir Rivest Adleman RSA

  • Slides: 37
Download presentation

RSA 알고리즘 9 1977년 RSA 알고리즘 등장 Shamir Rivest Adleman

RSA 알고리즘 9 1977년 RSA 알고리즘 등장 Shamir Rivest Adleman

RSA 온라인 Demo 11 RSA Demo in Javascript � � � http: //www-cs-students. stanford.

RSA 온라인 Demo 11 RSA Demo in Javascript � � � http: //www-cs-students. stanford. edu/~tjw/jsbn/rsa 2. html http: //asecuritysite. com/encryption/rsa 2 https: //www. hanewin. net/encrypt/rsa-test. htm

공개키 암호의 안전성 수학적으로 어려운 문제를 이용하여 설계 12 소인수분해 문제 (Integer Factorization Problem)

공개키 암호의 안전성 수학적으로 어려운 문제를 이용하여 설계 12 소인수분해 문제 (Integer Factorization Problem) � 합성수를 소수의 곱으로 나타내는 문제 easy Primes p, q n = pq hard 이산대수 문제 (Discrete Logarithm Problem) Given g, x, p x = logg y easy hard y = gx mod p Given g, y, p

RSA Factoring Challenge 15 소인수분해 문제 풀이

RSA Factoring Challenge 15 소인수분해 문제 풀이

공개키 암호 표준 (PKCS) 16 PKCS (Public-Key Cryptography Standard) � � RSA가 개발한 공개키

공개키 암호 표준 (PKCS) 16 PKCS (Public-Key Cryptography Standard) � � RSA가 개발한 공개키 암호 관련 표준 https: //www. emc. com/emc-plus/rsa-labs/standardsinitiatives/public-key-cryptography-standards. htm

키쌍의 생성 21 java. security. Key. Pair. Generator 클래스 � � � initialize( )

키쌍의 생성 21 java. security. Key. Pair. Generator 클래스 � � � initialize( ) 메소드를 호출하여 키의 크기, 사용할 난수 생성기, 알고리즘에 필요한 파라미터들을 초기화 가능 생성된 키는 java. security. Key. Pair에 유지 get. Public( ), get. Private( ) 메소드를 이용하여 키에 접근 공개키 객체 java. security. Public. Key 개인키 객체 java. security. Private. Key. Pair. Generator kpg = Key. Pair. Generator. get. Instance("RSA"); kpg. initialize(1024); Key. Pair key. Pair = kpg. generate. Key. Pair(); Public. Key pub. Key = key. Pair. get. Public(); Private. Key priv. Key = key. Pair. get. Private();

키의 인코딩 25 RSA 알고리즘의 경우 � � 공개키는 X. 509 인코딩을 사용. 공개키는

키의 인코딩 25 RSA 알고리즘의 경우 � � 공개키는 X. 509 인코딩을 사용. 공개키는 인증서와 함께 파일시 스템에 저장 개인키는 PKCS#8 인코딩을 사용. 개인키는 패스워드 기반 암호 화 방식을 통해 암호화된 상태로 저장 // 공개키쌍 생성 Key. Pair. Generator generator = Key. Pair. Generator. get. Instance(“RSA"); generator. initialize(1024); Key. Pair pair = generator. generate. Key. Pair(); Key public. Key = pair. get. Public(); Key private. Key = pair. get. Private(); System. out. println(“공개키 포맷 : “ + public. Key. get. Format()); System. out. println(“개인키 포맷 : “ + private. Key. get. Format()); 공개키 포맷 : X. 509 개인키 포맷 : PKCS#8

예제: Key. Factory. Example. java 27 // 공개키쌍 생성 Key. Pair. Generator generator =

예제: Key. Factory. Example. java 27 // 공개키쌍 생성 Key. Pair. Generator generator = Key. Pair. Generator. get. Instance("RSA"); generator. initialize(1024); Key. Pair pair = generator. generate. Key. Pair(); Public. Key public. Key = pair. get. Public(); Private. Key private. Key = pair. get. Private(); // 키를 바이트 스트림으로 변환 System. out. println("공개키 포맷 : " + public. Key. get. Format()); System. out. println("개인키 포맷 : " + private. Key. get. Format()); byte[] public. Key. Bytes = public. Key. get. Encoded(); byte[] private. Key. Bytes = private. Key. get. Encoded(); System. out. println("공개키 : "+bytes. To. Hex(public. Key. Bytes)); System. out. println("개인키 : "+bytes. To. Hex(private. Key. Bytes)); // 바이트 스트림을 키로 재변환 Key. Factory key. Factory = Key. Factory. get. Instance("RSA"); Public. Key pub. Key = key. Factory. generate. Public(new X 509 Encoded. Key. Spec(public. Key. Bytes)); Private. Key pri. Key = key. Factory. generate. Private(new PKCS 8 Encoded. Key. Spec(private. Key. Bytes)); System. out. println("복구된 공개키가 같은가? "+public. Key. equals(pub. Key)); System. out. println("복구된 개인키가 같은가? "+private. Key. equals(pri. Key)); // 키스펙 생성 및 키 상세정보 확인 Key. Factory fact = Key. Factory. get. Instance("RSA"); RSAPublic. Key. Spec public. Key. Spec = fact. get. Key. Spec(public. Key, RSAPublic. Key. Spec. class); RSAPrivate. Key. Spec private. Key. Spec = fact. get. Key. Spec(private. Key, RSAPrivate. Key. Spec. class); System. out. println("공개키 modulus: n = " + public. Key. Spec. get. Modulus()); System. out. println("공개키 exponent: e = " + public. Key. Spec. get. Public. Exponent()); System. out. println("개인키 modulus: n = " + private. Key. Spec. get. Modulus()); System. out. println("개인키 exponent: d = " + private. Key. Spec. get. Private. Exponent());

Cipher 클래스를 이용한 암호화/복호화 29 Cipher 객체 선언 � � Cipher cipher = Cipher.

Cipher 클래스를 이용한 암호화/복호화 29 Cipher 객체 선언 � � Cipher cipher = Cipher. get. Instance(“RSA”); Cipher cipher = Cipher. get. Instance(“RSA/ECB/PKCS 1 Padding”); 예제: RSAEncryption. java public static byte[] encrypt(Public. Key public. Key, byte[] plain. Data) throws General. Security. Exception { Cipher cipher = Cipher. get. Instance("RSA/ECB/PKCS 1 Padding"); cipher. init(Cipher. ENCRYPT_MODE, public. Key); byte[] encrypt. Data = cipher. do. Final(plain. Data); return encrypt. Data; } public static byte[] decrypt(Private. Key private. Key, byte[] encrypt. Data) throws General. Security. Exception { Cipher cipher = Cipher. get. Instance("RSA/ECB/PKCS 1 Padding"); cipher. init(Cipher. DECRYPT_MODE, private. Key); byte[] plain. Data = cipher. do. Final(encrypt. Data); return plain. Data; }

RSA 암호화/복호화 30 try{ Key. Pair. Generator kpg = Key. Pair. Generator. get. Instance("RSA");

RSA 암호화/복호화 30 try{ Key. Pair. Generator kpg = Key. Pair. Generator. get. Instance("RSA"); kpg. initialize(1024); Key. Pair key. Pair = kpg. gen. Key. Pair(); Public. Key pub. Key = key. Pair. get. Public(); Private. Key priv. Key = key. Pair. get. Private(); Cipher cipher = Cipher. get. Instance("RSA/ECB/PKCS 1 Padding"); cipher. init(Cipher. ENCRYPT_MODE, pub. Key); String plaintext = "This is a secret message!"; byte[] ciphertext = cipher. do. Final(plaintext. get. Bytes()); for(byte b: ciphertext) System. out. printf("%02 X ", b); System. out. println(); } } cipher. init(Cipher. DECRYPT_MODE, priv. Key); byte[] cleartext = cipher. do. Final(ciphertext); for(byte b: cleartext) System. out. print((char)b); System. out. println(); catch(){

PKCS 1 Padding 32 PKCS#1 v 1. 5에서의 패딩 방식 난수삽입 DATA 1998년 Bleichenbacher에

PKCS 1 Padding 32 PKCS#1 v 1. 5에서의 패딩 방식 난수삽입 DATA 1998년 Bleichenbacher에 의해 취약점 발견 � Adaptive chosen ciphertext attack (적응 선택 암호문 공격)

OAEP 34

OAEP 34

OAEP 35 public static byte[] encrypt(Public. Key public. Key, byte[] plain. Data) throws General.

OAEP 35 public static byte[] encrypt(Public. Key public. Key, byte[] plain. Data) throws General. Security. Exception { Cipher cipher = Cipher. get. Instance("RSA/ECB/OAEPWith. SHA-256 And. MGF 1 Padding"); cipher. init(Cipher. ENCRYPT_MODE, public. Key); byte[] encrypt. Data = cipher. do. Final(plain. Data); return encrypt. Data; } public static byte[] decrypt(Private. Key private. Key, byte[] encrypt. Data) throws General. Security. Exception { Cipher cipher = Cipher. get. Instance("RSA/ECB/OAEPWith. SHA-256 And. MGF 1 Padding"); cipher. init(Cipher. DECRYPT_MODE, private. Key); byte[] plain. Data = cipher. do. Final(encrypt. Data); return plain. Data; }

예제: Key. Transport. java 37 실행 결과

예제: Key. Transport. java 37 실행 결과