Вот возникла надобность закриптовать коннекшн стринг во
вью стейт
покопался и нашел пример рса криптования на VB по
адресу http://www.eggheadcafe.com/articles/20020630.asp
Отрефакторил малек, и сделал вот такой сишарп класс(без пояснения ибо сам еще
не успел разобраться
):
using System;
using System.Security.Cryptography;
namespace Controls
{
/// <summary>
/// Summary description for Cryptor.
/// </summary>
public class Cryptor
{
private CspParameters
cspParam;
private String publicKey;
private String privateKey;
public Cryptor()
{
cspParam = new CspParameters();
cspParam.Flags = CspProviderFlags.UseMachineKeyStore;
System.Security.Cryptography.RSACryptoServiceProvider
RSA = new System.Security.Cryptography.RSACryptoServiceProvider(cspParam);
publicKey = RSA.ToXmlString(false); //' gets the public key
privateKey = RSA.ToXmlString(true); //' gets the private key
}
public String Encrypt(string
str)
{
System.Security.Cryptography.RSACryptoServiceProvider
RSA2 = new System.Security.Cryptography.RSACryptoServiceProvider(cspParam);
RSA2.FromXmlString(privateKey);
byte[]
EncryptedStrAsByte = RSA2.Encrypt(System.Text.Encoding.Unicode.GetBytes(str),
false);
return
System.Text.Encoding.Unicode.GetString(EncryptedStrAsByte);
}
public String Decrypt(string
str)
{
System.Security.Cryptography.RSACryptoServiceProvider
RSA3 = new System.Security.Cryptography.RSACryptoServiceProvider(cspParam);
RSA3.FromXmlString(publicKey);
byte[]
Byte = RSA3.Decrypt(System.Text.Encoding.Unicode.GetBytes(str), false);
return
System.Text.Encoding.Unicode.GetString(Byte);
}
}
}