示例#1
0
 public void EncryptData01()
 {
     RSA rSA;
     string s;
     rSA = new RSA();
     s = rSA.EncryptData("data", "");
 }
示例#2
0
        public void ExtractExponent05()
        {
            string s;

            MLifter.Generics.RSA rsa = new MLifter.Generics.RSA();
            string key = rsa.GetPublicKey();

            s = Methods.ExtractExponent(key);
            Regex  regex = new Regex(@"<Exponent>(?<exponent>.+)</Exponent>", RegexOptions.Multiline);
            Match  m     = regex.Match(key);
            string mod   = String.Empty;

            if (!m.Success)
            {
                Assert.Fail("Could not match exponent!");
            }
            else
            {
                mod = Methods.Base64ToHex(m.Groups["exponent"].Value);
            }
            Assert.AreEqual <string>(mod, s);
        }
示例#3
0
 public void ExtractPublicKey05()
 {
     string s;
     MLifter.Generics.RSA rsa = new MLifter.Generics.RSA();
     string key = rsa.GetPublicKey();
     s = Methods.ExtractPublicKey(key);
     Regex regex = new Regex(@"<Modulus>(?<modulus>.+)</Modulus>", RegexOptions.Multiline);
     Match m = regex.Match(key);
     string mod = String.Empty;
     if (!m.Success)
     {
         Assert.Fail("Could not match modulus!");
     }
     else
     {
         mod = Methods.Base64ToHex(m.Groups["modulus"].Value);
     }
     Assert.AreEqual<string>(mod, s);
 }
示例#4
0
 public void EncryptData03()
 {
     RSA rSA;
     string s;
     rSA = new RSA();
     s = rSA.EncryptData("data", (string)null);
 }
示例#5
0
 public void EncryptData02()
 {
     RSA rSA;
     string s;
     rSA = new RSA();
     s = rSA.EncryptData("data", "<invalidxml>");
 }
示例#6
0
 public void VerifyData05()
 {
     RSA rSA;
     rSA = new RSA();
     byte[] bs = new byte[0];
     byte[] bs1 = new byte[0];
     byte[] bs2 = new byte[0];
     rSA.VerifyData(bs, bs1, (byte[])null, bs2);
 }
示例#7
0
 public void TestSignAndVerify()
 {
     for (int i = 0; i < 100; i++)
     {
         RSA rSA;
         rSA = new RSA();
         string data = TestInfrastructure.GetRandomString(TestInfrastructure.RandomGen.Next(1, 1000));
         Encoding enc = Encoding.Unicode;
         byte[] signature = rSA.SignData(enc.GetBytes(data), rSA.GetPrivateKey());
         byte[] mod = Methods.HexStringToByteArray(Methods.ExtractPublicKey(rSA.GetPublicKey()));
         byte[] exp = Methods.HexStringToByteArray(Methods.ExtractExponent(rSA.GetPublicKey()));
         rSA.VerifyData(enc.GetBytes(data), signature, mod, exp);
     }
 }
示例#8
0
 public void SignData04()
 {
     RSA rSA;
     byte[] bs;
     rSA = new RSA();
     bs = rSA.SignData(null, rSA.GetPrivateKey());
 }
示例#9
0
 public void SignData03()
 {
     RSA rSA;
     byte[] bs;
     rSA = new RSA();
     byte[] bs1 = new byte[0];
     bs = rSA.SignData(bs1, (string)null);
 }
示例#10
0
 public void SignData02()
 {
     RSA rSA;
     byte[] bs;
     rSA = new RSA();
     byte[] bs1 = new byte[0];
     bs = rSA.SignData(bs1, "");
 }
示例#11
0
 public void SignData01()
 {
     RSA rSA;
     byte[] bs;
     rSA = new RSA();
     byte[] bs1 = new byte[0];
     bs = rSA.SignData(bs1, "<invalidxml>");
 }
示例#12
0
 public void EncryptData04()
 {
     RSA rSA;
     string s;
     rSA = new RSA();
     s = rSA.EncryptData(null, rSA.GetPrivateKey());
 }