private static Cipher initializeCipherBasedOnServicePublicKey ( final PublicKey publicKey , final RegisteredService registeredService ) { try { LOGGER . debug ( "Using service [{}] public key [{}] to initialize the cipher" , registeredService . getServiceId ( ) , registeredService . getPublicKey ( ) ) ; val cipher = Cipher . getInstance ( publicKey . getAlgorithm ( ) ) ; cipher . init ( Cipher . ENCRYPT_MODE , publicKey ) ; LOGGER . debug ( "Initialized cipher in encrypt-mode via the public key algorithm [{}] for service [{}]" , publicKey . getAlgorithm ( ) , registeredService . getServiceId ( ) ) ; return cipher ; } catch ( final Exception e ) { LOGGER . warn ( "Cipher could not be initialized for service [{}]. Error [{}]" , registeredService , e . getMessage ( ) ) ; } return null ; }
Initialize cipher based on service public key .