RSA加密解密與簽名驗證

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   for   art   

關於RSACryption協助類定義見RSACryption

一、加密與解密

            //定義明文和密文變數            string plaintext = "天道酬勤,厚德載物!";            string ciphertext = "";            //產生密鑰            string prikey = "", pubkey = "";            rsa.RSAKey(out prikey, out pubkey);            //加密解密過程            ciphertext = rsa.RSAEncrypt(pubkey, plaintext);            plaintext = rsa.RSADecrypt(prikey, ciphertext);
View Code

 

二、簽名與驗證

            //擷取明文Hash值            byte[] plaintextHash = null;            rsa.GetHash(plaintext, ref plaintextHash);            //擷取簽名密文            string SignatureCiphertext = null;            rsa.SignatureFormatter(prikey, plaintextHash, ref SignatureCiphertext);            //驗證            string verify = rsa.SignatureDeformatter(pubkey, plaintextHash, SignatureCiphertext) ? "OK!沒問題" : "NO!內容被篡改了";
View Code

 

Tips:利用RSA的簽名和驗證功能還可簡單實現軟體註冊碼功能,簽名即註冊碼,驗證即驗證。

相關連結

RSA分段加密【解決“不正確的長度”的異常】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.