예제 #1
0
        public ExportedSecretKey(SecretKeyInfo keyInfo, /*ScryptInput secretInfo,*/ Encryption encryption)
        {
            KeyInfo = keyInfo;
            //SecretInfo = secretInfo;

            _encryption = encryption;
        }
예제 #2
0
        public static Task <SecretKey> NewSecretKey(SecretKeyInfo keyInfo, byte[] data)
        {
            return(Task.Run(() =>
            {
                // scrypt the data
                var result = ScryptEncoder.Encode(data);

                // get 16 bytes of the result and scyrpt it again
                var idData = new byte[16];
                Buffer.BlockCopy(result.Hash, 8, idData, 0, idData.Length);
                var idResult = ScryptEncoder.Encode(idData, result.IterationCount, result.BlockSize, result.ThreadCount, result.Salt);
                // use 8 bytes for id
                var id = BitConverter.ToUInt64(idResult.Hash, idData.Length);

                keyInfo.SecretId = id;
                return new SecretKey(keyInfo, result);
            }));
        }
예제 #3
0
        public static Task <SecretKey> NewSecretKey(SecretKeyInfo keyInfo, string password)
        {
            return(Task.Run(() =>
            {
                var pw = Encoding.UTF8.GetBytes(password);
                var iterations = Math.Abs(GetHashCode(pw)) % 100000;

                retry:

                var sha512 = new SHA512Managed();

                var hash = sha512.ComputeHash(pw);
                for (var i = 0; i < iterations; i++)
                {
                    hash = sha512.ComputeHash(hash);
                }

                var control = sha512.ComputeHash(pw);
                for (var i = 0; i < iterations; i++)
                {
                    control = sha512.ComputeHash(control);
                }

                if (!hash.SequenceEqual(control))
                {
                    goto retry;
                }

                var data = new byte[32];
                var salt = new byte[32];

                Buffer.BlockCopy(hash, 0, data, 0, 32);
                Buffer.BlockCopy(hash, 32, salt, 0, 32);

                return NewSecretKey(keyInfo, data, salt);
            }));
        }
예제 #4
0
 public ExportedSecretKey(Unpacker unpacker)
 {
     KeyInfo = SecretKeyInfo.Restore(unpacker);
     //SecretInfo = new ScryptInput(unpacker);
     _encryption = Encryption.Restore(new ArraySegment <byte>(unpacker.UnpackByteArray()));
 }
예제 #5
0
 public SecretKey(SecretKeyInfo keyInfo, /*ScryptInput scryptInfo,*/ byte[] secretHash)
 {
     KeyInfo = keyInfo;
     //SecretInfo = scryptInfo;
     SecretHash = secretHash;
 }
예제 #6
0
 SecretKey(SecretKeyInfo keyInfo, ScryptResult secret)
 {
     KeyInfo = keyInfo;
     //SecretInfo = secret.Input;
     SecretHash = secret.Hash;
 }
예제 #7
0
 public SecretKey(Unpacker unpacker)
 {
     KeyInfo = SecretKeyInfo.Restore(unpacker);
     //SecretInfo = new ScryptInput(unpacker);
     unpacker.Unpack(out SecretHash);
 }