public static string TestSCrypt(this Vector vector) { var derivedBytes = new byte[vector.Len]; SCrypt.ComputeKey(Encoding.ASCII.GetBytes(vector.Password), Encoding.ASCII.GetBytes(vector.Salt), vector.N, vector.R, vector.P, null, derivedBytes); var derived = new string(HexBase16.Encode(derivedBytes)); return(derived); }
public static string TestSHA1(this Vector vector) { var derivedBytes = new byte[vector.Len]; Pbkdf2.ComputeKey (Encoding.ASCII.GetBytes(vector.Password), Encoding.ASCII.GetBytes(vector.Salt), vector.C, Pbkdf2.CallbackFromHmac <HMACSHA1>(), 20, derivedBytes); var derived = new string(HexBase16.Encode(derivedBytes)); return(derived); }
public void TestBlowfish() { var vectors = Assembly.GetExecutingAssembly().GetManifestResourceStream("CryptTest.vectors.Blowfish.txt"); using (Stream stream = vectors) { using (var reader = new StreamReader(stream)) { string line; while ((line = reader.ReadLine()) != null) { Match match = Regex.Match(line, @"^([0-9A-z]{16})\s*([0-9A-z]{16})\s*([0-9A-z]{16})$"); if (!match.Success) { continue; } string key = match.Groups[1].Value, clear = match.Groups[2].Value, cipher = match.Groups[3].Value; byte[] keyBytes = HexBase16.Decode(key.ToCharArray()); byte[] clearBytes = HexBase16.Decode(clear.ToCharArray()); using (BlowfishCipher fish = BlowfishCipher.Create(keyBytes)) { var testCipherBytes = new byte[8]; fish.Encipher(clearBytes, 0, testCipherBytes, 0); var testCipher = new string(HexBase16.Encode(testCipherBytes)); Assert.AreEqual(cipher, testCipher, string.Format("Encipher failed test ({0} became {1})", cipher, testCipher)); var testClearBytes = new byte[8]; fish.Decipher(testCipherBytes, 0, testClearBytes, 0); var testClear = new string(HexBase16.Encode(testClearBytes)); Assert.AreEqual(clear, testClear, string.Format("Decipher failed ({0} became {1})", clear, testClear)); } } } } }