久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 Bouncy Castle 進行 C# RSA 解密

C# RSA Decryption using Bouncy Castle(使用 Bouncy Castle 進行 C# RSA 解密)
本文介紹了使用 Bouncy Castle 進行 C# RSA 解密的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我得到了一個 Base64 編碼的加密字符串,它是在 Java 中使用 Bouncy Castle 加密的.下面的示例 Java 代碼段:

I have been given a Base64 Encoded encrypted string, which was encrypted in Java using Bouncy Castle. Example 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);

我需要使用 Bouncy Castle 解密生成的字符串,但在 C# 中我已經獲得了有關如何在 Java 中執行此操作的代碼片段,但我無法將其轉換為 C#(原因是我們正在構建一個 .net 站點,并且將成為 Java 站點中的 iFrame.Java 站點將 RSA 加密字符串傳遞給 .NET 站點).下面要解密的示例 Java 代碼:

I need to decrypt the resulting string using Bouncy Castle, but in C# I have been given a code snippet on how to do this in Java, but I can't convert this for C# (reasons is we are building a .net site, and is going to be an iFrame within a Java site. The Java site is going to passing in the RSA Encrypted string to the .NET site). Example Java code to decrypt 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");

我已經從 http://www.bouncycastle.org/csharp/ 下載了示例,但是似乎沒有輸入字符串值進行加密的示例,然后通過加密/解密過程.

I have downloaded the examples from http://www.bouncycastle.org/csharp/ but there doesn't seem to be an example of inputting a string value to get encrypted, and it then going though the encrypt/decrypt process.

我得到了 模數、公共指數、私人指數、素數P、的值>prime qprime exponent pprime exponent qcrt coefficient.

I have been given values for modulus, public exponent, private expontent, prime P, prime q, prime exponent p, prime exponent q and crt coefficient.

我已經看到我可以使用以下內容:

I have seen that I can use the following:

IAsymmetricBlockCipher signer = new Pkcs1Encoding(new RsaEngine());
signer.Init(true, pubParameters);

但是 signer 對象似乎沒有與上面的 Java 示例相同的方法.

But the signer object doesn't seem to have the same methods as the Java examples above.

我唯一能用的方法是

ProcessBlock(byte[] inbuf, int inOff, int inLen);

但我看不出如何在我的上下文中使用它.

But I can't see how to use this in my context.

這里的任何幫助將不勝感激.

Any help here would be most appreciated.

推薦答案

為了幫助別人,最終轉換的代碼如下:

To Help others, the final code to convert is as follows:

RsaKeyParameters privParameters = new RsaPrivateCrtKeyParameters(mod, pubExp, privExp, p, q, pExp, qExp, crtCoef);
RsaKeyParameters pubParameters = new RsaKeyParameters(false, mod, pubExp);
IAsymmetricBlockCipher eng = new Pkcs1Encoding(new RsaEngine());
eng.Init(false, privParameters);
byte[] encdata = System.Convert.FromBase64String("{the enc string}");
encdata = eng.ProcessBlock(encdata, 0, encdata.Length);
string result = Encoding.UTF8.GetString(encdata);

mod、pubExp 等都是 BigInteger 值:

mod, pubExp etc etc are all BigInteger values:

static BigInteger mod = new BigInteger("big int value");

以下 using 指令是必需的:

The Following using directives are required:

using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Encodings;
using Org.BouncyCastle.Math;

這可以從 bouncycastle 網站獲得.http://www.bouncycastle.org/csharp/

Which can be obtained from the bouncycastle site. http://www.bouncycastle.org/csharp/

這篇關于使用 Bouncy Castle 進行 C# RSA 解密的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Java Remove Duplicates from an Array?(Java從數組中刪除重復項?)
How to fix Invocation failed Unexpected Response from Server: Unauthorized in Android studio(如何修復調用失敗來自服務器的意外響應:在 Android 工作室中未經授權)
AES encryption, got extra trash characters in decrypted file(AES 加密,解密文件中有多余的垃圾字符)
AES Error: Given final block not properly padded(AES 錯誤:給定的最終塊未正確填充)
Detecting incorrect key using AES/GCM in JAVA(在 JAVA 中使用 AES/GCM 檢測不正確的密鑰)
AES-256-CBC in Java(Java 中的 AES-256-CBC)
主站蜘蛛池模板: 网站黄色在线免费观看 | 亚洲国产精品99久久久久久久久 | 99久久精品国产麻豆演员表 | 久久激情av | 久久国内精品 | 午夜影院在线观看 | 国产精品国产三级国产aⅴ浪潮 | www.国产.com | 精品国产免费一区二区三区五区 | 国产一区二区免费在线 | 天天操操 | 久草免费在线视频 | 天天操夜夜艹 | 一本在线 | 欧美综合一区 | 精品日韩在线观看 | 日韩欧美在线观看 | www.五月婷婷.com | 成人免费日韩 | 亚洲欧美在线观看 | 日韩一区二区av | 亚洲一区二区三区国产 | 日韩精品久久一区二区三区 | 久久精品黄色 | 看av网 | 一级二级三级在线观看 | 午夜影院操 | 日韩一区二区在线视频 | 日韩中文一区二区三区 | 欧美日韩高清在线一区 | 在线午夜 | 国产精品欧美一区二区 | 天天躁日日躁狠狠的躁天龙影院 | 亚洲精品一区二区三区在线 | 久久国产精品无码网站 | 国产精品免费高清 | 免费的av网站 | 久久久亚洲 | 成人一区二区三区在线 | 欧美一区二区久久 | 欧美一区在线看 |