/** * Gets the encoded session key. * * @return the encoded session key * @throws GeneralSecurityException the general security exception */ public byte[] getEncodedSessionKey() throws GeneralSecurityException { SecretKey key = getSessionKey(); Cipher keyCipher = RSA_CIPHER.get(); keyCipher.init(Cipher.ENCRYPT_MODE, remotePublicKey); return keyCipher.doFinal(key.getEncoded()); }
/** * Decode data using session key. * * @param message the message * @return the byte[] * @throws GeneralSecurityException the general security exception */ public byte[] decodeData(byte[] message) throws GeneralSecurityException { if (sessionCipherPair == null) { sessionCipherPair = new CipherPair(SESSION_CRYPT_ALGORITHM, getSessionKey()); } return sessionCipherPair.decCipher.doFinal(message); }
/** * Encode data using sessionKey. * * @param message the message * @return the byte[] * @throws GeneralSecurityException the general security exception */ public byte[] encodeData(byte[] message) throws GeneralSecurityException { if (sessionCipherPair == null) { sessionCipherPair = new CipherPair(SESSION_CRYPT_ALGORITHM, getSessionKey()); } return sessionCipherPair.encCipher.doFinal(message); }