public static SecretKey getSecretKey ( InputStream keyInputStream , String entryName , String keyStorePassword ) throws KeyStoreException , NoSuchAlgorithmException , CertificateException , IOException , UnrecoverableEntryException { KeyStore keyStore = KeyStore . getInstance ( "JCEKS" ) ; if ( keyInputStream == null ) { throw new KeyStoreException ( "No Keystore stream provided." ) ; } if ( StringUtils . isEmpty ( keyStorePassword ) ) { throw new KeyStoreException ( "No Keystore password provided." ) ; } if ( StringUtils . isEmpty ( entryName ) ) { throw new KeyStoreException ( "No Keystore entry name provided." ) ; } keyStore . load ( keyInputStream , keyStorePassword . toCharArray ( ) ) ; KeyStore . ProtectionParameter protectionParameter = new KeyStore . PasswordProtection ( keyStorePassword . toCharArray ( ) ) ; KeyStore . SecretKeyEntry pkEntry = ( KeyStore . SecretKeyEntry ) keyStore . getEntry ( entryName , protectionParameter ) ; try { return pkEntry . getSecretKey ( ) ; } finally { keyInputStream . close ( ) ; } }
Method which will load a secret key from an input stream with the specified entry name .