public static byte[] Encrypt(byte[] data, KeyPair kp) { byte[] raw; using (var rsa = new RSACryptoServiceProvider()) { rsa.ImportCspBlob(Decompress(Base32.FromBase32String(kp.Public))); raw = rsa.Encrypt(data, true); } return raw; }
public static KeyPair CreateNew(int length) { KeyPair ret; using (var rsa = new RSACryptoServiceProvider(length)) { try { var pub = rsa.ExportCspBlob(false); var priv = rsa.ExportCspBlob(true); ret = new KeyPair(Base32.ToBase32String(Compress(pub)), Base32.ToBase32String(Compress(priv))); } finally { rsa.PersistKeyInCsp = false; } } return ret; }
public static bool VerifyData(KeyPair kp, byte[] data, byte[] signature) { bool b; using (var rsa = new RSACryptoServiceProvider()) { rsa.ImportCspBlob(Decompress(Base32.FromBase32String(kp.Public))); b = rsa.VerifyData(data, new SHA1CryptoServiceProvider(), signature); } return b; }
public static byte[] Sign(KeyPair kp, byte[] data) { byte[] signature; using(var rsa = new RSACryptoServiceProvider()) { rsa.ImportCspBlob(Decompress(Base32.FromBase32String(kp.Private))); signature = rsa.SignData(data, new SHA1CryptoServiceProvider()); } return signature; }