我收到了一个Base64编码的加密字符串,使用Bouncy Castle在Java中加密。以下是示例Java代码:
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);
我需要使用Bouncy Castle在C#中解密结果字符串。我已经得到了一个Java代码片段,但我无法将其转换为C#(原因是我们正在构建一个.NET网站,并且将成为Java网站内的iFrame。 Java网站将传递RSA加密字符串到.NET网站)。以下是解密示例Java代码:
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");
我已从http://www.bouncycastle.org/csharp/下载了示例,但似乎没有输入字符串值以获取加密结果并通过加密/解密过程的示例。
我已经获得了模数、公共指数、私人指数、质数P、质数q、质数指数p、质数指数q和crt系数的值。
我看到可以使用以下内容:
IAsymmetricBlockCipher signer = new Pkcs1Encoding(new RsaEngine());
signer.Init(true, pubParameters);
但是,
signer
对象似乎没有与上述Java示例相同的方法。我唯一能使用的方法是:
ProcessBlock(byte[] inbuf, int inOff, int inLen);
但是我无法看到如何在我的情况下使用它。任何帮助将不胜感激。