Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void calculateSessionKeySupport(PrivateKey y, PublicKey gToTheX) {
- try {
- // Find g^xy
- KeyAgreement serverKeyAgree = KeyAgreement.getInstance("DiffieHellman");
- serverKeyAgree.init(y);
- serverKeyAgree.doPhase(gToTheX, true);
- byte[] secretDH = serverKeyAgree.generateSecret();
- if (debug) System.out.println("g^xy: "+byteArrayToHexString(secretDH));
- //Use first 16 bytes of g^xy to make an AES key
- byte[] aesSecret = new byte[16];
- System.arraycopy(secretDH,0,aesSecret,0,16);
- Key aesSessionKey = new SecretKeySpec(aesSecret, "AES");
- if (debug) System.out.println("Session key: "+byteArrayToHexString(aesSessionKey.getEncoded()));
- // Set up Cipher Objects
- decAESsessionSupport = Cipher.getInstance("AES");
- decAESsessionSupport.init(Cipher.DECRYPT_MODE, aesSessionKey);
- encAESsessionSupport = Cipher.getInstance("AES");
- encAESsessionSupport.init(Cipher.ENCRYPT_MODE, aesSessionKey);
- } catch (NoSuchAlgorithmException e ) {
- System.out.println(e);
- } catch (InvalidKeyException e) {
- System.out.println(e);
- } catch (NoSuchPaddingException e) {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement