Esempio n. 1
0
 public void Base64ToHex04()
 {
     for (int i = 0; i <= 100; i++)
     {
         string input   = TestInfrastructure.GetRandomString(TestInfrastructure.RandomGen.Next(15, 1000));
         string s       = Methods.Base64ToHex(Convert.ToBase64String(Encoding.ASCII.GetBytes(input)));
         string reverse = Encoding.ASCII.GetString(Methods.HexStringToByteArray(s));
         Assert.AreEqual <string>(input, reverse);
     }
 }
Esempio n. 2
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);
     }
 }
Esempio n. 3
0
        public void CompressedArrayStringHexStringLengthComparison()
        {
            for (int k = 0; k < 100; k++)
            {
                // generate the random string and corresponding byte array
                string input = TestInfrastructure.GetRandomString(TestInfrastructure.RandomGen.Next(2, 100));
                byte[] bs    = new byte[input.Length];
                for (int i = 0; i < input.Length; i++)
                {
                    bs[i] = (byte)input[i];
                }

                // encode the byte array both as compressed string and hex string
                string compressedStr = Methods.ByteArrayToCompressedArrayString(bs);
                string hexStr        = Methods.ByteArrayToHexString(bs);

                Assert.IsTrue(compressedStr.Length <= hexStr.Length);
            }
        }
Esempio n. 4
0
        public void ByteArrayToCompressedArrayStringRandom()
        {
            for (int k = 0; k < 100; k++)
            {
                string input = TestInfrastructure.GetRandomString(TestInfrastructure.RandomGen.Next(2, 100));
                byte[] bs    = new byte[input.Length];
                for (int i = 0; i < input.Length; i++)
                {
                    bs[i] = (byte)input[i];
                }
                string step1 = Methods.ByteArrayToCompressedArrayString(bs);
                byte[] bs2   = Methods.CompressedArrayStringToByteArray(step1, input.Length);
                string step2 = String.Empty;
                for (int i = 0; i < bs2.Length; i++)
                {
                    step2 += (char)bs2[i];
                }

                Assert.AreEqual <string>(input, step2);
            }
        }