c sharp string encryption source code
- 2020-05-05 11:46:56
- OfStack
You can use DSA and RSA, e.g.
using System;
using System.Text;
using System.Security.Cryptography;
class dsacrypto_SignData {
public static void Main(String[] args){
// first convert the string to a byte array, which is all about encoding.
String str = "this is a test.";
byte[] bytes = Encoding.ASCII.GetBytes(str);
// select the signature method, RSA and DSA
DSACryptoServiceProvider dsac = new DSACryptoServiceProvider();
byte[] sign = dsac.SignData(bytes);
//sign is the signature result.
// below is
certified DSACryptoServiceProvider dsac2 = new DSACryptoServiceProvider();
dsac2.FromXmlString(dsac.ToXmlString(false));
bool ver = dsac2.VerifyData(bytes, sign);
if (ver) {
Console. WriteLine (" by ");
} else {
Console.WriteLine(" cannot pass ");
}
}
}
RSA is similar, but RSA is much slower than DSA, but safer than DSA. RSA can choose the size of the keyword, the larger the safer
using System;
using System.Text;
using System.Security.Cryptography;
class dsacrypto_SignData {
public static void Main(String[] args){
// first convert the string to a byte array, which is all about encoding.
String str = "this is a test.";
byte[] bytes = Encoding.ASCII.GetBytes(str);
// select the signature method, RSA and DSA
DSACryptoServiceProvider dsac = new DSACryptoServiceProvider();
byte[] sign = dsac.SignData(bytes);
//sign is the signature result.
// below is
certified DSACryptoServiceProvider dsac2 = new DSACryptoServiceProvider();
dsac2.FromXmlString(dsac.ToXmlString(false));
bool ver = dsac2.VerifyData(bytes, sign);
if (ver) {
Console. WriteLine (" by ");
} else {
Console.WriteLine(" cannot pass ");
}
}
}
RSA is similar, but RSA is much slower than DSA, but safer than DSA. RSA can choose the size of the keyword, the larger the safer