外部サービスから暗号化された文字列を取得しています。これを復号化し、BouncyCastle APIを使用して再暗号化する必要があります。
復号化はうまくいきましたが、暗号化はうまくいかないようです。暗号化方法によって生成された文字列を復号化しようとするInvalidCipherTextException
と、「不明なブロック タイプ」というメッセージが表示されます。
これは、インターフェイスしているサービスからのテキストを正常に復号化する復号化コードです。
string Decrypt(string value)
{
string Signature = "My_Signature";
RsaKeyParameters keyParams = (RsaKeyParameters)PublicKeyFactory.CreateKey(Convert.FromBase64String(Signature));
IBufferedCipher cipher = CipherUtilities.GetCipher("RSA/NONE/PKCS1Padding");
cipher.Init(false, keyParams);
byte[] secretBytes = Convert.FromBase64String(value);
byte[] decrypted = cipher.DoFinal(secretBytes);
return Encoding.Default.GetString(decrypted);
}
これは私の暗号化方法であり、私の復号化方法が処理できる暗号化された文字列を生成していないようです:
string Encrypt(string value)
{
string Signature = "My_Signature";
RsaKeyParameters keyParams = (RsaKeyParameters)PublicKeyFactory.CreateKey(Convert.FromBase64String(Signature));
IBufferedCipher cipher = CipherUtilities.GetCipher("RSA/NONE/PKCS1Padding");
cipher.Init(true, keyParams);
byte[] secretBytes = Encoding.Default.GetBytes(value);
byte[] encrypted = cipher.DoFinal(secretBytes);
return Convert.ToBase64String(encrypted);
}
この作業を行うために何が欠けているのかよくわかりません。ここに欠けていると思われる明らかなものはありますか?