RSA加密字符串公共密钥RSA公共密钥
我给定的公共密钥是在
string publicKey =
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlUCQZso6P43gKqw0CfTlwYb3N+m4v6IME 4nPA3WXe52wFpDM/JCFWSdXa7BewlwzDYjblgwL4u59CPxNTPTh7LTD4xXOaGDJHjX5+YgqK4fb9rs ImjMpIACrND/LAdrq5mctWWzw3UtW3F+o+sNwIZM8n65ysS+Vhq9IypFlfuQbWrKjAcWZ3u1iLtplz yf/pjhOEyyZiBUnh6D219+pMiE9nhCpc4xkH1gnlGszIDBqZMMULtGJvFXydA1vv5HxxCYJ2ydEzmA KYxVgA9BGXPEGE89dQbeJsieTj+FSsp9oTm+4vi345opRvH8DWhmZc4OPSwBEL8pwgS7cUnKPtwIDA QAB";
Java中的示例代码中的一行中,需要将公共密钥转换为RSA公共密钥。 下面的行是否将字符串公钥转换为rsapublickey? C#中有对应物吗?
byte[] decoedPublicKey = Base64.getDecoder().decode(publicKey);
RSAPublicKey rsaPublicKey = (RSAPublicKey) KeyFactory.getInstance("RSA").
generatePublic(new X509EncodedKeySpec(decoedPublicKey));
我试图将RSA加密消息发送到外部API,并且始终将API返回无法解密消息的错误。我不是在我的C#应用中执行此步骤,这是正确的RSA加密所需的公共密钥所必需的。下面是我的RSA加密的片段。正确吗?
Pkcs1Encoding pkcs1Encoding = new Pkcs1Encoding((IAsymmetricBlockCipher)new RsaEngine());
using (StringReader reader = new StringReader(publicKey))
{
AsymmetricKeyParameter parameters = (AsymmetricKeyParameter)new PemReader((TextReader)reader).ReadObject();
pkcs1Encoding.Init(true, (ICipherParameters)parameters);
}
return Convert.ToBase64String(pkcs1Encoding.ProcessBlock(bytes, 0, bytes.Length));
The given public key to me is in this string format
string publicKey =
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlUCQZso6P43gKqw0CfTlwYb3N+m4v6IME 4nPA3WXe52wFpDM/JCFWSdXa7BewlwzDYjblgwL4u59CPxNTPTh7LTD4xXOaGDJHjX5+YgqK4fb9rs ImjMpIACrND/LAdrq5mctWWzw3UtW3F+o+sNwIZM8n65ysS+Vhq9IypFlfuQbWrKjAcWZ3u1iLtplz yf/pjhOEyyZiBUnh6D219+pMiE9nhCpc4xkH1gnlGszIDBqZMMULtGJvFXydA1vv5HxxCYJ2ydEzmA KYxVgA9BGXPEGE89dQbeJsieTj+FSsp9oTm+4vi345opRvH8DWhmZc4OPSwBEL8pwgS7cUnKPtwIDA QAB";
One line in the sample code in java that the public key needs to be converted to RSA Public key.
Does the lines below converts a string public key to RSAPublicKey? Is there a counterpart in C#?
byte[] decoedPublicKey = Base64.getDecoder().decode(publicKey);
RSAPublicKey rsaPublicKey = (RSAPublicKey) KeyFactory.getInstance("RSA").
generatePublic(new X509EncodedKeySpec(decoedPublicKey));
I am trying to send an RSA encrypted message to an external API and always the api returns an error that it could not decrypt the message. I am not doing this step in my c# app, is this required in correct RSA encryption of the public key. Below is a snippet of my RSA encryption. Is it correct?
Pkcs1Encoding pkcs1Encoding = new Pkcs1Encoding((IAsymmetricBlockCipher)new RsaEngine());
using (StringReader reader = new StringReader(publicKey))
{
AsymmetricKeyParameter parameters = (AsymmetricKeyParameter)new PemReader((TextReader)reader).ReadObject();
pkcs1Encoding.Init(true, (ICipherParameters)parameters);
}
return Convert.ToBase64String(pkcs1Encoding.ProcessBlock(bytes, 0, bytes.Length));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论