Skip to content Skip to sidebar Skip to footer

Java Rsa Decryption Not Working, Throws Invalidkeyspecexception

I used phpseclib to generate RSA public and private key. $rsa = new Crypt_RSA(); $rsa->setHash('sha1'); $rsa->setMGFHash('sha1'); $rsa->setEncryptionMode(CRYPT_RSA_ENCRY

Solution 1:

Try this branch of phpseclib:

https://github.com/terrafrost/phpseclib/tree/pkcs8/phpseclib

And instead of $rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1); do $rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS8);

The thing is... Java is expecting a PKCS8 key. A PKCS8 key starts with -----BEGIN PRIVATE KEY----- instead of -----BEGIN RSA PRIVATE KEY-----.

Post a Comment for "Java Rsa Decryption Not Working, Throws Invalidkeyspecexception"