Java Cryptography Programming Overview 2017

slide1 n.w
1 / 37
Embed
Share

Explore a comprehensive overview of Java Cryptography Programming in 2017, covering topics such as JCA/JCE, PKI, RSA, DSA, ECDSA, and more. Learn about digital signature algorithms like DSA and RSA, and delve into the world of encryption and security protocols. Discover the significance of cryptographic techniques in Java programming and enhance your knowledge in this specialized domain.

  • Java Cryptography
  • Programming
  • Security
  • Encryption
  • Algorithms

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. 1 JAVA CRYPTOGRAPHY PROGRAMMING 2017. 3.

  2. 2 1. 2. 3. 4. 5. JCA/JCE 6. , MAC, 7. , / 8. 9. 10. (PKI) 11. /

  3. 9. 3

  4. 1. ? 4 ?

  5. ? 5

  6. 6

  7. 7 A B

  8. 8 , ,

  9. 9

  10. 10 RSA ElGamal DSA NIST 1991 Nyberg-Rueppel KCDSA ECDSA DSA GQ Schnorr

  11. RSA 11 RSA RSA (sign) : (verify) : . 1 ?

  12. RSA 12 https://kjur.github.io/jsrsasign/sample-rsasign.html

  13. DSA (Digital Signature Algorithm) 13 1991 NIST DSS DSA . DSS DSA . ( ) Y=g^x mod p Y, g, p x

  14. ECDSA 14 (Elliptic Curve Digital Signature Algorithm)

  15. 2. JCA/JCE 15 java.security.Signature / getInstance( ) < >with< > Signature signature = Signature.getInstance( SHA1withRSA );

  16. Signature 16 Signature

  17. Signature 17

  18. 18 DSA (Digital Signature Algorithm) RSA (Rivest Shamir Adleman) EC (Elliptic Curve, )

  19. 19 RSA DSA EC

  20. : SignatureExample.java 20 // public static byte[] sign(PrivateKey privateKey, byte[] plainData) throws GeneralSecurityException { Signature signature = Signature.getInstance("SHA256withRSA"); signature.initSign(privateKey); signature.update(plainData); byte[] signatureData = signature.sign(); return signatureData; } // public static boolean verify(PublicKey publicKey, byte[] signatureData, byte[] plainData) throws GeneralSecurityException { Signature signature = Signature.getInstance("SHA256withRSA"); signature.initVerify(publicKey); signature.update(plainData); return signature.verify(signatureData); }

  21. RSA 21 : SignatureExample.java KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); generator.initialize(2048); KeyPair pair = generator.generateKeyPair(); Signature signature = Signature.getInstance("SHA256withRSA"); signature.initSign(privateKey); signature.update(plainData); byte[] signatureData = signature.sign(); RSA

  22. DSA 22 : SignatureExampleDSA.java KeyPairGenerator generator = KeyPairGenerator.getInstance( DSA"); generator.initialize(2048); KeyPair pair = generator.generateKeyPair(); Signature signature = Signature.getInstance("SHA256withDSA"); signature.initSign(privateKey); signature.update(plainData); byte[] signatureData = signature.sign(); DSA

  23. ECDSA () 23 : SignatureExampleECDSA.java KeyPairGenerator generator = KeyPairGenerator.getInstance( EC"); generator.initialize(256); KeyPair pair = generator.generateKeyPair(); Key size must be at most 571 bits Signature signature = Signature.getInstance(" SHA256withECDSA"); signature.initSign(privateKey); signature.update(plainData); byte[] signatureData = signature.sign(); ECDSA

  24. RSA 24 RSA . RSA/PSS Probabilistic Signature Scheme Salt Salt

  25. RSA/PSS 25 Bouncy Castle RSA/PSS : SignatureExampleRSAPSS.java , SHA256withRSA/PSS SHA256withRSAandMGF1 BC import org.bouncycastle.jce.provider.BouncyCastleProvider; Security.addProvider(new BouncyCastleProvider()); Signature signature = Signature.getInstance("SHA256withRSA/PSS");

  26. Bouncycastle 26 Jar https://www.bouncycastle.org/latest_releases.html bcprov-jdk15on-159.jar

  27. Bouncycastle 27 JAR : -> -> (Properties)->Java Build Path->Libraries->Add External JARs-> jar ->OK

  28. RSA/PSS 28 : SignatureExampleRSAPSS.java : 30820122300d06092a864886f70d01010105000382010f003082010a0282010100a23fe711474a008dbd258dd1a51ed5010a0f83d5e0a1930f110684e15 : 308204bc020100300d06092a864886f70d0101010500048204a6308204a20201000282010100a23fe711474a008dbd258dd1a51ed5010a0f83d5e0a1930 : . : 829d875834653dc879722f2b9db12393fc0e7e80af53c9f67c8d936a022e3f2bf52800e3823079046d179581dab7b173c3106ac7c50c86616706b97d12b = true : 30820122300d06092a864886f70d01010105000382010f003082010a0282010100a23fe711474a008dbd258dd1a51ed5010a0f83d5e0a1930f110684e15 : 308204bc020100300d06092a864886f70d0101010500048204a6308204a20201000282010100a23fe711474a008dbd258dd1a51ed5010a0f83d5e0a1930 : . : 02da554201b075edb51e5a74933f121260cc46ed85b871ee6641bf12b2a187b516e7995815ff3412a720cf98a0f29da8d1fccda88ffb613c3a83e7df4df = true : 30820122300d06092a864886f70d01010105000382010f003082010a0282010100a23fe711474a008dbd258dd1a51ed5010a0f83d5e0a1930f110684e15 : 308204bc020100300d06092a864886f70d0101010500048204a6308204a20201000282010100a23fe711474a008dbd258dd1a51ed5010a0f83d5e0a1930 : . : 59e1d46d1ea5a301e7e24c8cd637f40f587b43f5830d28cbaba33e1a64aa4156e92bb59ac40878bfb1832916e6c0b6446d9522d42fc044fd89649eb7b51 = true

  29. (Digital Envelope) 29 3 : : : 1. 2. 3. 1. 2. 3.

  30. 30 Randomly Generated Session Key Bob s Public Key/Private Key Alice s Public Key Symmetric Key Cryptosystem Encrypted Message Encryption Encrypted Session Key Encrypted Message Hash Algorithm Signature Hash SEND Signing Encrypted Session Key Public Key Cryptosystem Encryption Signature

  31. 31 Bob s Public Key Alice s Public Key/Private Key Encrypted Session Key Signature Decryption Verifying Encrypted Session Key Encrypted Message Hash Algorithm Hash1 Hash2 RECEIVE Encrypted Message Decryption Signature

  32. 32 AES / // AES public static byte[] encrypt(SecretKey secretKey, byte[] plainData) throws GeneralSecurityException { Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); byte[] encryptData = cipher.doFinal(plainData); return encryptData; } // AES public static byte[] decrypt(SecretKey secretKey, byte[] encryptData) throws GeneralSecurityException { Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, secretKey); byte[] plainData = cipher.doFinal(encryptData); return plainData; }

  33. 33 RSA / // RSA public static byte[] encrypt(PublicKey publicKey, byte[] plainData) throws GeneralSecurityException { Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithMD5AndMGF1Padding"); cipher.init(Cipher.ENCRYPT_MODE, publicKey); byte[] encryptData = cipher.doFinal(plainData); return encryptData; } // RSA public static byte[] decrypt(PrivateKey privateKey, byte[] encryptData) throws GeneralSecurityException { Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithMD5AndMGF1Padding"); cipher.init(Cipher.DECRYPT_MODE, privateKey); byte[] plainData = cipher.doFinal(encryptData); return plainData; }

  34. 34 RSA / // RSA public static byte[] sign(PrivateKey privateKey, byte[] plainData) throws GeneralSecurityException { Signature signature = Signature.getInstance("SHA256withRSA/PSS"); signature.initSign(privateKey); signature.update(plainData); byte[] signatureData = signature.sign(); return signatureData; } // RSA public static boolean verify(PublicKey publicKey, byte[] signatureData, byte[] plainData) throws GeneralSecurityException { Signature signature = Signature.getInstance("SHA256withRSA/PSS"); signature.initVerify(publicKey); signature.update(plainData); return signature.verify(signatureData); }

  35. 35 System.out.println("3. A "); String plainText = " ."; System.out.println(" : "+plainText); Charset charset = Charset.forName("UTF-8"); // byte[] signature = sign(privateKeyA, plainText.getBytes(charset)); System.out.println(" : "+bytesToHex(signature)); // AES KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); keyGenerator.init(128); SecretKey secretKey = keyGenerator.generateKey(); System.out.println(" : "+bytesToHex(secretKey.getEncoded())); // byte[] encryptData = encrypt(secretKey, plainText.getBytes(charset)); byte[] encryptSig = encrypt(secretKey, signature); System.out.println("AES : "+bytesToHex(encryptData)); System.out.println("AES : "+bytesToHex(encryptSig)); // B byte[] encryptKey = encrypt(publicKeyB, secretKey.getEncoded()); System.out.println("RSA : "+bytesToHex(encryptKey)); System.out.println();

  36. 36 System.out.println("4. B "); // B byte[] decryptKey = decrypt(privateKeyB, encryptKey); System.out.println(" : "+bytesToHex(decryptKey)); // SecretKeySpec SecretKey recoveredKey = new SecretKeySpec(decryptKey, "AES"); // , byte[] plainData = decrypt(recoveredKey, encryptData); String plain = new String(plainData, charset); byte[] sig = decrypt(recoveredKey, encryptSig); System.out.println(" :"+plain); System.out.println(" :"+bytesToHex(sig)); // A boolean verified = verify(publicKeyA, sig, plainData); System.out.println(" = " + verified);

  37. : Envelope.java 37

Related


More Related Content