예제 #1
0
        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;
        }
예제 #2
0
        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;
        }
예제 #3
0
        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;
        }
예제 #4
0
        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;
        }