/** * Convenience method that returns the cipher key to use for <em>both</em> encryption and decryption. * <p/> * <b>N.B.</b> This method can only be called if the underlying {@link #getCipherService() cipherService} is a symmetric * CipherService which by definition uses the same key for both encryption and decryption. If using an asymmetric * CipherService public/private key pair, you cannot use this method, and should instead use the * {@link #getEncryptionCipherKey()} and {@link #getDecryptionCipherKey()} methods individually. * <p/> * The default {@link AesCipherService} instance is a symmetric cipher service, so this method can be used if you are * using the default. * * @return the symmetric cipher key used for both encryption and decryption. */ public byte[] getCipherKey() { //Since this method should only be used with symmetric ciphers //(where the enc and dec keys are the same), either is fine, just return one of them: return getEncryptionCipherKey(); }
/** * Encrypts the byte array by using the configured {@link #getCipherService() cipherService}. * * @param serialized the serialized object byte array to be encrypted * @return an encrypted byte array returned by the configured {@link #getCipherService () cipher}. */ protected byte[] encrypt(byte[] serialized) { byte[] value = serialized; CipherService cipherService = getCipherService(); if (cipherService != null) { ByteSource byteSource = cipherService.encrypt(serialized, getEncryptionCipherKey()); value = byteSource.getBytes(); } return value; }
/** * Convenience method that returns the cipher key to use for <em>both</em> encryption and decryption. * <p/> * <b>N.B.</b> This method can only be called if the underlying {@link #getCipherService() cipherService} is a symmetric * CipherService which by definition uses the same key for both encryption and decryption. If using an asymmetric * CipherService public/private key pair, you cannot use this method, and should instead use the * {@link #getEncryptionCipherKey()} and {@link #getDecryptionCipherKey()} methods individually. * <p/> * The default {@link AesCipherService} instance is a symmetric cipher service, so this method can be used if you are * using the default. * * @return the symmetric cipher key used for both encryption and decryption. */ public byte[] getCipherKey() { //Since this method should only be used with symmetric ciphers //(where the enc and dec keys are the same), either is fine, just return one of them: return getEncryptionCipherKey(); }
/** * Encrypts the byte array by using the configured {@link #getCipherService() cipherService}. * * @param serialized the serialized object byte array to be encrypted * @return an encrypted byte array returned by the configured {@link #getCipherService () cipher}. */ protected byte[] encrypt(byte[] serialized) { byte[] value = serialized; CipherService cipherService = getCipherService(); if (cipherService != null) { ByteSource byteSource = cipherService.encrypt(serialized, getEncryptionCipherKey()); value = byteSource.getBytes(); } return value; }
/** * Convenience method that returns the cipher key to use for <em>both</em> encryption and decryption. * <p/> * <b>N.B.</b> This method can only be called if the underlying {@link #getCipherService() cipherService} is a symmetric * CipherService which by definition uses the same key for both encryption and decryption. If using an asymmetric * CipherService public/private key pair, you cannot use this method, and should instead use the * {@link #getEncryptionCipherKey()} and {@link #getDecryptionCipherKey()} methods individually. * <p/> * The default {@link AesCipherService} instance is a symmetric cipher service, so this method can be used if you are * using the default. * * @return the symmetric cipher key used for both encryption and decryption. */ public byte[] getCipherKey() { //Since this method should only be used with symmetric ciphers //(where the enc and dec keys are the same), either is fine, just return one of them: return getEncryptionCipherKey(); }
/** * Encrypts the byte array by using the configured {@link #getCipherService() cipherService}. * * @param serialized the serialized object byte array to be encrypted * @return an encrypted byte array returned by the configured {@link #getCipherService () cipher}. */ protected byte[] encrypt(byte[] serialized) { byte[] value = serialized; CipherService cipherService = getCipherService(); if (cipherService != null) { ByteSource byteSource = cipherService.encrypt(serialized, getEncryptionCipherKey()); value = byteSource.getBytes(); } return value; }