Code Monkey home page Code Monkey logo

hstardemoproject's Introduction

Hi there 👋

hstardemoproject's People

Contributors

dependabot[bot] avatar hstarorg avatar npmcdn-to-unpkg-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hstardemoproject's Issues

关于C#rsa解密的问题,代码里面引用了BouncyCastle.CS文件,但是解出来的结果乱码

代码如下:
static void Main(string[] args)
{

        var rsaHelper = new RsaHelper();
        var test1 =
           "i0s9lv0QuefmmXWkWxqIwJMcK1/uOjTTIpc0K2YWAwFGuMSbQ651Zfl4i7MY/Qi/vG8+J7SRyb3UWiS5CNP3M3MI2tC6l2CVAGv0godSMaeWbMqj9g17KwJr9r3EYtPvc8lRi8ec3qS8plkoPUCoz3PtsK LZ9hBlAXKD3f8qGDI=";
        var key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxtkuwBI6novN6IKoP3AUe7vQnT +3NqYy0SJqGTf4u5sWuKj6jwpvBSf17DoBGAXPVfzQjtl3xNymn/87c7qzDzollBH1dXAdg5olwp0tAUVEWDKuCgaFGjsqnrTYxTvOqTf1J08mIQf3Tngkw1WuNBdADUiBsTlgpO9k+ffIL4wIDAQAB";
        var source = rsaHelper.DecryptByPublibKey(test1, key);
        Console.WriteLine("通过公钥解密后的原文是:{0}", source);

        Console.ReadKey();

    }

///

    /// 公钥解密(key公钥解密)- 必须对应私钥加密
    /// </summary>


    /// <param name="source">加密后的数据(密文)</param>
    /// <param name="publicKey">公钥</param>
    /// <returns></returns>
    public string DecryptByPublibKey(string source, string publicKey)
    {
        var publicInfoByte = Convert.FromBase64String(publicKey);
        Asn1Object pubKeyObj = Asn1Object.FromByteArray(publicInfoByte);//这里也可以从流中读取,从本地导入  
        AsymmetricKeyParameter pubKey = PublicKeyFactory.CreateKey(SubjectPublicKeyInfo.GetInstance(pubKeyObj));
        //开始解密
        IAsymmetricBlockCipher cipher = new RsaEngine();
        cipher.Init(false, pubKey);
        //解密已加密的数据
        byte[] encryptedData = Convert.FromBase64String(source);
        encryptedData = cipher.ProcessBlock(encryptedData, 0, encryptedData.Length);
        return Encoding.UTF8.GetString(encryptedData, 0, encryptedData.Length);
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.