private byte[] BcScrypt(char[] password, byte[] salt, int costParameter, int blocksize, int parallelizationParam) { return(SCrypt.Generate(PbeParametersGenerator.Pkcs5PasswordToUtf8Bytes(password), salt, costParameter, blocksize, parallelizationParam, 256 / 8)); }
public void DeriveKeyTest() { int N = 32, r = 2, p = 2; var derivedkey = SCrypt.Generate(new byte[] { 0x01, 0x02, 0x03 }, new byte[] { 0x04, 0x05, 0x06 }, N, r, p, 64).ToHexString(); Assert.AreEqual("b6274d3a81892c24335ab46a08ec16d040ac00c5943b212099a44b76a9b8102631ab988fa07fb35357cee7b0e3910098c0774c0e97399997676d890b2bf2bb25", derivedkey); }
public string Hash(string salt, int length) { var S = Encoding.UTF8.GetBytes(salt); var hash = SCrypt.Generate(passBytes, S, N, r, p, length); var result = Convert.ToBase64String(hash); return(result); }
/// <summary> /// Use Scrypt to generate 48 bytes hash. /// Scrypt is used instead of Bscrypt because Bscrypt cannot work when importing the wallet /// </summary> /// <param name="salt">salt</param> /// <param name="pwd">password</param> /// <returns>the generated 48 bytes hash</returns> public static byte[] GenerateHash(byte[] salt, string pwd) { if (salt.Length != 16) { return(null); } var password = Encoding.UTF8.GetBytes(pwd); const int SCryptN = 262144; return(SCrypt.Generate(password, salt, SCryptN, 8, 1, 48)); }
private void CheckIllegal(String msg, byte[] pass, byte[] salt, int N, int r, int p, int len) { try { SCrypt.Generate(pass, salt, N, r, p, len); Fail(msg); } catch (ArgumentException e) { //Console.Error.WriteLine(e.StackTrace); } }
public void TestVectors() { using (StreamReader sr = new StreamReader(SimpleTest.GetTestDataAsStream("scrypt.TestVectors.txt"))) { int count = 0; string line = sr.ReadLine(); while (line != null) { ++count; string header = line; StringBuilder data = new StringBuilder(); while (!IsEndData(line = sr.ReadLine())) { data.Append(line.Replace(" ", "")); } int start = header.IndexOf('(') + 1; int limit = header.LastIndexOf(')'); string argStr = header.Substring(start, limit - start); string[] args = argStr.Split(','); byte[] P = ExtractQuotedString(args[0]); byte[] S = ExtractQuotedString(args[1]); int N = ExtractInteger(args[2]); int r = ExtractInteger(args[3]); int p = ExtractInteger(args[4]); int dkLen = ExtractInteger(args[5]); byte[] expected = Hex.Decode(data.ToString()); // This skips very expensive test case(s), remove check to re-enable if (N <= 16384) { byte[] result = SCrypt.Generate(P, S, N, r, p, dkLen); if (!AreEqual(expected, result)) { Fail("Result does not match expected value in test case " + count); } } } } }
public string DoGenerateSCrypt(string password, string salt, int CPUCost, int blockSize, int parallelization, int keyLenght) { this.error.cleanError(); if (!areSCRyptValidParameters(CPUCost, blockSize, parallelization)) { return(""); } EncodingUtil eu = new EncodingUtil(); byte[] encryptedBytes = SCrypt.Generate(eu.getBytes(password), Hex.Decode(salt), CPUCost, blockSize, parallelization, keyLenght); string result = Base64.ToBase64String(encryptedBytes); if (result == null || result.Length == 0) { this.error.setError("PD009", "SCrypt generation error"); return(""); } this.error.cleanError(); return(result); }
public static byte[] GenerateDerivedScryptKey( byte[] password, byte[] salt, int n, int r, int p, int dkLen) { return(SCrypt.Generate(password, salt, n, r, p, dkLen)); }