java - RSA - bouncycastle PEMReader returning PEMKeyPair instead of AsymmetricCipherKeyPair for reading private key -
i have function reads openssl formatted private key: static asymmetrickeyparameter readprivatekey(string privatekeyfilename) { asymmetriccipherkeypair keypair; using (var reader = file.opentext(privatekeyfilename)) keypair = (asymmetriccipherkeypair)new pemreader(reader).readobject(); return keypair.private; } and returns asymmetrickeyparameter used decrypt encrypted text. below decrypt code: public static byte[] decrypt3(byte[] data, string pemfilename) { string result = ""; try { asymmetrickeyparameter key = readprivatekey(pemfilename); rsaengine e = new rsaengine(); e.init(false, key); //byte[] cipheredbytes = getbytes(encryptedmsg); //debug.log (encryptedmsg); byte[] cipheredbytes = e.processblock(data, 0, data.length); //result = encoding.utf8.getstring(cipheredbytes); //return result; return cipheredbytes; } catch (exception e) { debug.log (...