How to distinguish between encrypted/unencrypted key in a PEM file

Bartlomiej bartek at conclusive.pl
Wed Jan 26 14:14:20 UTC 2022


Hello,

I have a PEM file on the device which can contain an 
encrypted/non-encrypted private key. When it's encrypted, it's using 
PBES/PBKDF. The file is accessed from a C++ application which uses the 
OpenSSL library. If the key is encrypted, then it should be PKCS#8, but 
checking it is PKCS#8 by using e.g. `PEM_read_PKCS8` is not enough to 
confirm it is actually encrypted, since an unencrypted key can also be 
stored as PKCS#8. Is there a way to check whether the key is encrypted 
or not using OpenSSL APIs?

Best regards,
Bartlomiej Nowak


More information about the openssl-users mailing list