Beispiel #1
0
        public void StringCrypt_Basic_TripleDES()
        {
            string input = "test 123 %$#";

            byte[] output      = StringCrypt.EncryptTripleDES(input);
            string outputFinal = StringCrypt.DecryptTripleDES(output);

            Assert.AreEqual(input, outputFinal, "String output should be as exected after decrypt.");
        }
Beispiel #2
0
        public void StringCrypt_Specific_RSA_KeySize()
        {
            string       input     = "foobar and some special characters $%^&*()";
            RSACryptInfo cryptInfo = new RSACryptInfo(1024);

            byte[] output      = StringCrypt.EncryptRSA(input, cryptInfo);
            string outputFinal = StringCrypt.DecryptRSA(output, cryptInfo);

            Assert.AreEqual(input, outputFinal, "String output should be as exected after decrypt.");
        }
Beispiel #3
0
        public void StringCrypt_Specific_TripleDES_NewAlg()
        {
            string    input = "foobar and some special characters $%^&*()";
            TripleDES alg   = TripleDES.Create("TripleDES");

            byte[] output      = StringCrypt.EncryptTripleDES(input, alg);
            string outputFinal = StringCrypt.DecryptTripleDES(output, alg);

            Assert.AreEqual(input, outputFinal, "String output should be as exected after decrypt.");
        }
Beispiel #4
0
    public static void SetLogin()
    {
        var Cookie = new HttpCookie(
            "U",
            StringCrypt.Encrypt(Convert.ToBase64String(StringCrypt.GetSHA1(HttpContext.Current.Request.UserAgent + HttpContext.Current.Request.UserHostAddress)), "eri01268")
            );

        Cookie.HttpOnly = true;
        HttpContext.Current.Response.Cookies.Add(Cookie);
    }
Beispiel #5
0
        public void StringCrypt_Specific_TripleDES_WrongAlg()
        {
            string    input = "foobar and some special characters $%^&*()";
            TripleDES alg1  = TripleDES.Create("TripleDES");
            TripleDES alg2  = TripleDES.Create("TripleDES");

            byte[] output      = StringCrypt.EncryptTripleDES(input, alg1);
            string outputFinal = StringCrypt.DecryptTripleDES(output, alg2);

            Assert.AreNotEqual(input, outputFinal, "String output should not be decryptable.");
        }
Beispiel #6
0
        public void StringCrypt_Specific_RFC2898_Salt()
        {
            string           input     = "foobar and some special characters $%^&*()";
            RFC2898CryptInfo cryptInfo = new RFC2898CryptInfo();

            cryptInfo.salt = "RandomSalt12634asdf";

            byte[] output      = StringCrypt.EncryptRfc2898(input, cryptInfo);
            string outputFinal = StringCrypt.DecryptRfc2898(output, cryptInfo);

            Assert.AreEqual(input, outputFinal, "String output should be as exected after decrypt.");
        }
Beispiel #7
0
        public void StringCrypt_Specific_RFC2898_Password()
        {
            string           input     = "foobar and some special characters $%^&*()";
            RFC2898CryptInfo cryptInfo = new RFC2898CryptInfo();

            cryptInfo.password = "******";

            byte[] output      = StringCrypt.EncryptRfc2898(input, cryptInfo);
            string outputFinal = StringCrypt.DecryptRfc2898(output, cryptInfo);

            Assert.AreEqual(input, outputFinal, "String output should be as exected after decrypt.");
        }
Beispiel #8
0
        public void StringCrypt_Converter()
        {
            string str = "LongString with @#$@# stuff in it!?.";

            byte[] input = Encoding.UTF8.GetBytes(str);

            string base64 = StringCrypt.ConvertByteArrayToBase64(input);

            byte[] output = StringCrypt.ConvertBase64ToByteArray(base64);

            Assert.AreEqual(input, output, "The converted back and forth should be identical");
        }
Beispiel #9
0
        public void StringCrypt_Specific_RFC2898_VIKey()
        {
            string           input     = "foobar and some special characters $%^&*()";
            RFC2898CryptInfo cryptInfo = new RFC2898CryptInfo();

            cryptInfo.VIKey = "abc12366FFTYYU^d";

            byte[] output      = StringCrypt.EncryptRfc2898(input, cryptInfo);
            string outputFinal = StringCrypt.DecryptRfc2898(output, cryptInfo);

            Assert.AreEqual(input, outputFinal, "String output should be as exected after decrypt.");
        }
Beispiel #10
0
        public void StringCrypt_Specific_RSA_WrongPrivatKey()
        {
            string       input        = "foobar and some special characters $%^&*()";
            RSACryptInfo cryptInfo1   = new RSACryptInfo(512);
            RSACryptInfo cryptInfo2   = new RSACryptInfo(512);
            RSACryptInfo cryptInfoKey = new RSACryptInfo(512);

            cryptInfo2.privateKey = cryptInfoKey.privateKey;

            byte[] output      = StringCrypt.EncryptRSA(input, cryptInfo1);
            string outputFinal = StringCrypt.DecryptRSA(output, cryptInfo2);

            Assert.AreNotEqual(input, outputFinal, "String output should not be decryptable.");
        }
Beispiel #11
0
        public void StringCrypt_Specific_RSA_CustomKeys()
        {
            string       input        = "foobar and some special characters $%^&*()";
            RSACryptInfo cryptInfo    = new RSACryptInfo(512);
            RSACryptInfo cryptInfoKey = new RSACryptInfo(512);

            cryptInfo.publicKey  = cryptInfoKey.publicKey;
            cryptInfo.privateKey = cryptInfoKey.privateKey;

            byte[] output      = StringCrypt.EncryptRSA(input, cryptInfo);
            string outputFinal = StringCrypt.DecryptRSA(output, cryptInfo);

            Assert.AreEqual(input, outputFinal, "String output should be as exected after decrypt.");
        }
Beispiel #12
0
        public void StringCrypt_Specific_RFC2898_WrongVIKey()
        {
            string           input      = "foobar and some special characters $%^&*()";
            RFC2898CryptInfo cryptInfo1 = new RFC2898CryptInfo();

            cryptInfo1.VIKey = "983GET$%I8876824";
            RFC2898CryptInfo cryptInfo2 = new RFC2898CryptInfo();

            cryptInfo2.VIKey = "Sdfert@$#G53df$#";

            byte[] output      = StringCrypt.EncryptRfc2898(input, cryptInfo1);
            string outputFinal = StringCrypt.DecryptRfc2898(output, cryptInfo2);

            Assert.AreNotEqual(input, outputFinal, "String output should not be decryptable.");
        }
Beispiel #13
0
        public void StringCrypt_Specific_RFC2898_WrongSalt()
        {
            string           input      = "foobar and some special characters $%^&*()";
            RFC2898CryptInfo cryptInfo1 = new RFC2898CryptInfo();

            cryptInfo1.salt = "salt1ABCD";
            RFC2898CryptInfo cryptInfo2 = new RFC2898CryptInfo();

            cryptInfo2.salt = "salt2ABCD";

            byte[] output      = StringCrypt.EncryptRfc2898(input, cryptInfo1);
            string outputFinal = StringCrypt.DecryptRfc2898(output, cryptInfo2);

            Assert.AreNotEqual(input, outputFinal, "String output should not be decryptable.");
        }
Beispiel #14
0
        public void StringCrypt_Specific_RFC2898_WrongPassword()
        {
            string           input      = "foobar and some special characters $%^&*()";
            RFC2898CryptInfo cryptInfo1 = new RFC2898CryptInfo();

            cryptInfo1.password = "******";
            RFC2898CryptInfo cryptInfo2 = new RFC2898CryptInfo();

            cryptInfo2.password = "******";

            byte[] output      = StringCrypt.EncryptRfc2898(input, cryptInfo1);
            string outputFinal = StringCrypt.DecryptRfc2898(output, cryptInfo2);

            Assert.AreNotEqual(input, outputFinal, "String output should not be decryptable.");
        }
Beispiel #15
0
        public override string ReadJson(JsonReader reader, Type objectType, string existingValue, bool hasExistingValue, JsonSerializer serializer)
        {
            var result = string.Empty;

            try
            {
                var val = StringCrypt.DecryptString((string)reader.Value, _cryptPass);

                if (!string.IsNullOrWhiteSpace(val) && val.StartsWith(_cryptCheck))
                {
                    result = val.Replace(_cryptCheck, string.Empty);
                }
            }
            catch (Exception e)
            {
                Log.O("Error decrypting string: {0}", e);
            }

            return(result);
        }
Beispiel #16
0
 public override void WriteJson(JsonWriter writer, string value, JsonSerializer serializer)
 {
     writer.WriteValue(StringCrypt.EncryptString(_cryptCheck + value, _cryptPass));
 }