古詩詞大全網 - 藝術簽名 - 有沒有知道怎樣用C語言來寫RSA加密算法的代碼的?謝謝

有沒有知道怎樣用C語言來寫RSA加密算法的代碼的?謝謝

#region RSA的加密函數 //##############################################################################

//RSA 方式加密

//說明KEY必須是XML的行式,返回的是字符串

//在有壹點需要說明!!該加密方式有 長度 限制的!!

//##############################################################################

//RSA的加密函數 string public string RSAEncrypt(string xmlPublicKey, string m_strEncryptString)

{

byte[] PlainTextBArray; byte[] CypherTextBArray;

string Result;

RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();

rsa.FromXmlString(xmlPublicKey);

PlainTextBArray = (new UnicodeEncoding()).GetBytes(m_strEncryptString);

CypherTextBArray = rsa.Encrypt(PlainTextBArray, false);

Result = Convert.ToBase64String(CypherTextBArray);

return Result;

} //RSA的加密函數 byte[]

public string RSAEncrypt(string xmlPublicKey, byte[] EncryptString)

{

byte[] CypherTextBArray; string Result;

RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();

rsa.FromXmlString(xmlPublicKey);

CypherTextBArray = rsa.Encrypt(EncryptString, false);

Result = Convert.ToBase64String(CypherTextBArray);

return Result;

} #endregion

#region RSA的解密函數 //RSA的解密函數 string

public string RSADecrypt(string xmlPrivateKey, string m_strDecryptString)

{

byte[] PlainTextBArray;

byte[] DypherTextBArray;

string Result;

System.Security.Cryptography.RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();

rsa.FromXmlString(xmlPrivateKey);

PlainTextBArray = Convert.FromBase64String(m_strDecryptString);

DypherTextBArray = rsa.Decrypt(PlainTextBArray, false);

Result = (new UnicodeEncoding()).GetString(DypherTextBArray);

return Result;

}

//RSA的解密函數 byte public string RSADecrypt(string xmlPrivateKey, byte[] DecryptString)

{

byte[] DypherTextBArray;

string Result;

System.Security.Cryptography.RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();

rsa.FromXmlString(xmlPrivateKey);

DypherTextBArray = rsa.Decrypt(DecryptString, false);

Result = (new UnicodeEncoding()).GetString(DypherTextBArray);

return Result;

} #endregion

#endregion