public void setCertificate ( ) throws KeyStoreException , IOException , NoSuchAlgorithmException , CertificateException , NoSuchPaddingException , InvalidKeyException , IllegalBlockSizeException , BadPaddingException , UnrecoverableEntryException { KeyStore store = KeyStore . getInstance ( this . keystore_type ) ; InputStream inputStream = Thread . currentThread ( ) . getContextClassLoader ( ) . getResourceAsStream ( this . keystore_path ) ; if ( inputStream == null ) inputStream = new FileInputStream ( this . keystore_path ) ; store . load ( inputStream , this . keystore_password ) ; this . cipher = Cipher . getInstance ( this . cipher_type ) ; this . certificate = ( X509Certificate ) store . getCertificate ( this . cert_alias ) ; log . debug ( "certificate = " + this . certificate . toString ( ) ) ; this . cipher . init ( Cipher . ENCRYPT_MODE , this . certificate ) ; this . encryptedToken = this . cipher . doFinal ( this . auth_value . getBytes ( ) ) ; KeyStore . PrivateKeyEntry privateKey = ( KeyStore . PrivateKeyEntry ) store . getEntry ( this . cert_alias , new KeyStore . PasswordProtection ( this . cert_password ) ) ; this . certPrivateKey = privateKey . getPrivateKey ( ) ; this . valueSet = true ; }
Used during setup to get the certification from the keystore and encrypt the auth_value with the private key