Var rsa = DotNetUtilities.ToRSA(pemObject) Var pemReader = new pemObject = (Org.Bounc圜)pemReader.ReadObject() You're using the wrong PemReader, you want the one from Org.Bounc圜astle.OpenSsl.ĮDIT: For some reason OP is insistent that this class has no ReadObject method. How do I read RSA public key from PEM file and use it to encrypt in Bounc圜astle in C#? Var decrypted = (decryptEngine.ProcessBlock(bytesToDecrypt, 0, bytesToDecrypt.Length)) Var decryptEngine = new Pkcs1Encoding(new RsaEngine()) ĭecryptEngine.Init(false, keyPair.Private) KeyPair = (AsymmetricCipherKeyPair) new PemReader(reader).ReadObject() Using (var reader = // file containing RSA PKCS1 private key This is the code: var bytesToDecrypt = Convert.FromBase64String("la0Cz.D43g=") // string to decrypt, base64 encoded In case anyone's interested, bouncycastle did the trick, just took me some time due to lack of knowledge from on my side and documentation. this will print the original unencrypted stringĬonsole.WriteLine((decryptedBytes)) Rsa.ImportFromPem(privateKey.ToCharArray()) Ĭonvert.FromBase64String(""), To try the code snippet below, generate a keypair and encrypt some text at var privateKey = RSA PRIVATE KEY.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |