I am new in java. I have certificate file ( .cer, Signature algorithm name: SHA1withRSA ) file. And their requirement is to encrypt user password in web application.
I got several link over google none of them using .cer file extention,i imported that file in our key store using
keytool -importcert -file C:\Users\Admin\Downloads\xyz.cer -keystore test.jks -alias demo
i am getting these key using following code :
public SecretKey getSecretKey(final String typeKeyStore,
final String pathToKeyStore,
final String storePassword,
final String keyAlias,
final String aliasPassword) throws KeyStoreException,
IOException, CertificateException, NoSuchAlgorithmException, UnrecoverableEntryException {
KeyStore ks = KeyStore.getInstance(typeKeyStore);
ks.load(new FileInputStream(pathToKeyStore),
storePassword.toCharArray());
SecretKeyEntry entry = (SecretKeyEntry) ks.getEntry(
keyAlias,
new KeyStore.PasswordProtection(aliasPassword
.toCharArray()));
return entry.getSecretKey();
}
Following Exception is comming :
Exception in thread "main" java.lang.UnsupportedOperationException: trusted certificate entries are not password-protected
at java.security.KeyStoreSpi.engineGetEntry(Unknown Source)
at java.security.KeyStore.getEntry(Unknown Source)
at com.aes256.MyAESCrypto.getSecretKey(MyAESCrypto.java:71)
at com.aes256.MyAESCrypto.main(MyAESCrypto.java:100)
Can any one help me whether i am right ?