I was provided with a Base64 encoded encrypted string that was encrypted in Java using Bouncy Castle. An example of a Java snippet below:
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); cipher.init(Cipher.ENCRYPT_MODE, key.getPublic()); byte[] encryptedText = cipher.doFinal("xxxxx|xxxxx".getBytes("UTF-8")); String encodedText = new BASE64Encoder().encode(encryptedText);
I need to decrypt the resulting string using Bouncy Castle, but in C # I was provided with a piece of code on how to do this in Java, but I canβt convert it for C # (the reason is that we are building a .net site and we will be an iFrame on a Java site. going to send an encrypted string to the RSA to the .NET site). Sample Java code for decryption below:
Cipher cipherDec = Cipher.getInstance("RSA/ECB/PKCS1Padding"); cipherDec.init(Cipher.DECRYPT_MODE, key.getPrivate()); byte[] decodedText = new BASE64Decoder().decodeBuffer(encodedText); byte[] decryptedText = cipherDec.doFinal(decodedText); String finalValue = new String(decryptedText, "UTF-8");
I downloaded examples from http://www.bouncycastle.org/csharp/ , but there seems to be no example of entering a string value for encryption, and then it goes through the encryption / decryption process.
I am assigned values ββfor the module , public exponent , private indicator , prime P , prime q , prime index p , prime index q and coefficient crt .
I saw that I can use the following:
IAsymmetricBlockCipher signer = new Pkcs1Encoding(new RsaEngine()); signer.Init(true, pubParameters);
But the signer object does not seem to have the same methods as the Java examples above.
Only method that I can use
ProcessBlock(byte[] inbuf, int inOff, int inLen);
But I do not see how to use this in my context.
Any help here would be most appreciated.
java c # cryptography rsa bouncycastle
mp3duck
source share