RSA使用私钥解密。 [英] RSA Decryption using private key.

查看:102
本文介绍了RSA使用私钥解密。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一种加密解密软件。我使用RSA加密来加密我的对称密钥。



我按照链接中提供的代码



https://msdn.microsoft.com/en-us/library/bb397867(v = vs.110).aspx [ ^ ]



我的加密和解密在同一台机器上成功完成。但是当我尝试从其他计算机解密时,出现错误:发生了错误的数据。(它可以从同一台机器解密。)



如何将我的公钥发布到其他系统以解密不同的系统。







请帮帮我,给我一个从不同机器解密的想法。

I am developing an encryption decryption software.I used RSA encryption to encypt my symmetric key.

I followed the code provided in the link

https://msdn.microsoft.com/en-us/library/bb397867(v=vs.110).aspx[^]

My encryption and decryption done successfully in same machine.But when I tried to decrypt from other computer,an error :bad data is occuring.(It can be decrypted from same machine.)

How to publish my public key to other systems inorder to decrypt form different system.



Please help me ,give me an idea to decrypt from different machines.

public void GetPrivateKey()
        {
            string c;
           
            cspp.KeyContainerName = keyName;

            rsa = new RSACryptoServiceProvider(cspp);
            rsa.PersistKeyInCsp = true;
            
            if (rsa.PublicOnly == true)
                c= "Key: " + cspp.KeyContainerName + " - Public Only";
            else
                c = "Key: " + cspp.KeyContainerName + " - Full Key Pair";
        }
 public string decryptkey(string at)
        {
            byte[] KeyEncrypted;
            KeyEncrypted = File.ReadAllBytes(at);
            //System.IO.File.ReadAllBytes(at);//for good 
           
            objr.GetPrivateKey();
           byte[] KeyDecrypted = objr.rsa.Decrypt(KeyEncrypted, false);
            string skey = GetString(KeyDecrypted);
            return skey;
        }





错误数据此行发生错误,

byte [] KeyDecrypted = objr .rsa.Decrypt(KeyEncrypted,false);





请..



Bad data Error happens in this line,
byte[] KeyDecrypted = objr.rsa.Decrypt(KeyEncrypted, false);.


Please..

推荐答案

这个问题毫无意义。私钥始终是私有的,它不需要通过网络传递,也永远不应该通过网络传递。你错过了公钥加密的整个想法。你必须学习它,因为它非常重要。所以,请参阅: https://en.wikipedia.org/wiki/Public-key_cryptography [ ^ ]。



简而言之:用一个密钥加密,用另一个密钥解密。如果目的是加密(不是数字签名),则通过网络发送的密钥只是加密的密钥,解密的密钥保密。如果您不知道如何处理它,请了解Alice和Bob的所作所为。



-SA
The question makes no sense. The private key is always private, it does not need to be passed through the network, and never ever should be. You are missing the whole idea of public-key encryption. You have to learn it, because it's very important. So, please see: https://en.wikipedia.org/wiki/Public-key_cryptography[^].

In brief: you encrypt with one key, decrypt with another one. If the purpose is encryption (not digital signature), the key sent over network is only the key to encrypt, and the key to decrypt is kept private. If you don't see what to do with it, learn from what Alice and Bob do.

—SA


这篇关于RSA使用私钥解密。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆