Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01CifR2BE7PBvRy5hT8TS9oz
21 lines
1.2 KiB
Plaintext
21 lines
1.2 KiB
Plaintext
$ java --enable-preview -cp ... EncryptedKeys (27.0.1.0.2+1)
|
|
== write an encrypted key with the defaults
|
|
[-----BEGIN ENCRYPTED PRIVATE KEY-----, -----END ENCRYPTED PRIVATE KEY-----]
|
|
default algorithm: PBEWithHmacSHA256AndAES_128
|
|
default iteration count: 4096, salt bytes: 20
|
|
== read it back
|
|
ok: withDecryption(password) returns the original key
|
|
== choose the algorithm and cost yourself
|
|
PBEWithHmacSHA512AndAES_256, iterations 600000
|
|
ok: getKey(password) on the decoded EncryptedPrivateKeyInfo works too
|
|
== a file written by openssl pkcs8 -topk8 -v2 aes-256-cbc
|
|
PBEWithHmacSHA256AndAES_256
|
|
ok: decrypts to the same key as the unencrypted file
|
|
== failures
|
|
no password, ask for PrivateKey !! java.lang.ClassCastException: Cannot cast javax.crypto.EncryptedPrivateKeyInfo to java.security.PrivateKey
|
|
no password, no class -> EncryptedPrivateKeyInfo PBEWithHmacSHA256AndAES_256
|
|
wrong password !! javax.crypto.CryptoException: java.security.InvalidKeyException: Cannot retrieve the PKCS8EncodedKeySpec
|
|
password on a key that is not encrypted -> PrivateKey RSA
|
|
openssl 'traditional' encrypted (Proc-Type: 4,ENCRYPTED) !! java.lang.IllegalArgumentException: java.security.InvalidKeyException: Invalid PKCS#1 encoding
|
|
exit=0
|