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在 c# 中使用 Bouncy Castle,当我使用以下代码使用加密文本和私钥解密时:

keyPair = (AsymmetricCipherKeyPair)new PemReader(reader).ReadObject();
IAsymmetricBlockCipher cipher = new RsaEngine();
RsaKeyParameters privateKey = (RsaKeyParameters)keyPair.Private;
cipher.Init(false, keyPair.Private);
byte[] deciphered = cipher.ProcessBlock(bytesl, 0, bytesl.Length);
string decipheredText = utf8enc.GetString(deciphered);

我得到 decipheredText 为

☻♣?????U??`?u????|???^H?|???☺????♦M>?→?&↔.0p?J??a?▼?S←$*▬T☼?  xQ??-??Ai9;??siqD??_???  ♥↓§?k?Ny??kr?U??↔z Mazher Ul Haq

但我的实际字符串是“Mazher Ul Haq”,如何获取实际字符串

4

1 回答 1

2

您的“加密文本”实际上是 base64 文本。我怀疑如果你先把它转换成非base64数据,你应该没问题。如果您已经将其作为字符串获取,则很简单:

byte[] binaryData = Convert.FromBase64String(base64Text);

如果您需要先将其转换为字符串:

string base64Text = Encoding.ASCII.GetString(base64Binary);
byte[] binaryData = Convert.FromBase64String(base64Text);
于 2013-09-18T17:51:18.673 回答