Вопрос

I have function which creates big-integer values. I want to use these values as secret-keys entries to the Keystore. I want to know if there is way of adding these Big-integer values as secret keys to the keystore. I tried to cast cast big-integer value to secret-key but it am getting an error that big-integer could not be casted to secret-key. here is the bestI have got so far.

KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
char[] password = "ps".toByteArray();
ks.load(null, password);
....
BigInteger sect=getsect();
javax.crypto.SecretKey mySecretKey=(SecretKey)sect;
KeyStore.SecretKeyEntry skEntry =
    new KeyStore.SecretKeyEntry(mySecretKey);
ks.setEntry("secretKeyAlias", skEntry, 
    new KeyStore.PasswordProtection(password));

since this is not working I do not know how I could add a value I wish as secretkey to the keystore. below is the error message I am getting

java.math.BigInteger cannot be cast to javax.crypto.SecretKey
Это было полезно?

Решение

  • a tutorials
  • generateSecret() api

    PBEKeySpec keySpec = new PBEKeySpec(password.toCharArray());

    SecretKeyFactory kf = SecretKeyFactory.getInstance("PBEWithMD5AndDES");

    SecretKey passwordKey = kf.generateSecret(keySpec);

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top