コード例 #1
0
ファイル: Generate.cs プロジェクト: smalltsky/Kryptor
 public static byte[] KeyEncryptionKey(byte[] sharedSecret, byte[] ephemeralSharedSecret, byte[] salt)
 {
     byte[] inputKeyingMaterial = Utilities.ConcatArrays(sharedSecret, ephemeralSharedSecret);
     byte[] keyEncryptionKey    = Blake2.KeyDerivation(inputKeyingMaterial, salt, Constants.EncryptionKeyLength);
     Utilities.ZeroArray(ephemeralSharedSecret);
     Utilities.ZeroArray(inputKeyingMaterial);
     return(keyEncryptionKey);
 }
コード例 #2
0
ファイル: Generate.cs プロジェクト: tej0402/Kryptor
 public static byte[] KeyEncryptionKey(byte[] sharedSecret, byte[] ephemeralSharedSecret, byte[] salt)
 {
     byte[] inputKeyingMaterial = Arrays.Concat(sharedSecret, ephemeralSharedSecret);
     byte[] keyEncryptionKey    = Blake2.KeyDerivation(inputKeyingMaterial, salt, Constants.EncryptionKeyLength);
     CryptographicOperations.ZeroMemory(ephemeralSharedSecret);
     CryptographicOperations.ZeroMemory(inputKeyingMaterial);
     return(keyEncryptionKey);
 }
コード例 #3
0
ファイル: Password.cs プロジェクト: smalltsky/Kryptor
 public static byte[] Hash(char[] password)
 {
     if (password.Length == 0)
     {
         return(null);
     }
     byte[] passwordBytes = GetPasswordBytes(password);
     return(Blake2.Hash(passwordBytes));
 }
コード例 #4
0
ファイル: DigitalSignatures.cs プロジェクト: tej0402/Kryptor
 private static byte[] GetFileBytes(string filePath, bool preHash)
 {
     if (!preHash)
     {
         return(File.ReadAllBytes(filePath));
     }
     using var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, Constants.FileStreamBufferSize, FileOptions.SequentialScan);
     return(Blake2.Hash(fileStream));
 }
コード例 #5
0
 public static byte[] ReadKeyfile(string keyfilePath)
 {
     using var keyfile = new FileStream(keyfilePath, FileMode.Open, FileAccess.Read, FileShare.Read, Constants.FileStreamBufferSize, FileOptions.SequentialScan);
     if (keyfile.Length == Constants.KeyfileLength)
     {
         byte[] keyfileBytes = new byte[Constants.KeyfileLength];
         keyfile.Read(keyfileBytes, offset: 0, keyfileBytes.Length);
         return(keyfileBytes);
     }
     return(Blake2.Hash(keyfile));
 }
コード例 #6
0
        private static byte[] GetFileBytes(string filePath, bool preHashed)
        {
            int  oneGibibyte = 1024 * Constants.Mebibyte;
            long fileSize    = FileHandling.GetFileLength(filePath);

            if (fileSize >= oneGibibyte || preHashed)
            {
                using var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, Constants.FileStreamBufferSize, FileOptions.SequentialScan);
                return(Blake2.Hash(fileStream));
            }
            return(File.ReadAllBytes(filePath));
        }
コード例 #7
0
        public static bool Compare(char[] a, char[] b)
        {
            // Constant time comparison
            byte[] aBytes = Encoding.UTF8.GetBytes(a);
            byte[] aHash  = Blake2.Hash(aBytes);
            CryptographicOperations.ZeroMemory(aBytes);
            byte[] bBytes = Encoding.UTF8.GetBytes(b);
            byte[] bHash  = Blake2.Hash(bBytes);
            CryptographicOperations.ZeroMemory(bBytes);
            bool equal = Utilities.Compare(aHash, bHash);

            CryptographicOperations.ZeroMemory(aHash);
            CryptographicOperations.ZeroMemory(bHash);
            return(equal);
        }
コード例 #8
0
ファイル: Password.cs プロジェクト: smalltsky/Kryptor
 private static byte[] CombineKeyfileAndPassword(byte[] passwordBytes, byte[] keyfileBytes)
 {
     passwordBytes = Blake2.KeyedHash(passwordBytes, keyfileBytes);
     Utilities.ZeroArray(keyfileBytes);
     return(passwordBytes);
 }
コード例 #9
0
ファイル: Password.cs プロジェクト: tej0402/Kryptor
 private static byte[] CombineKeyfileAndPassword(byte[] passwordBytes, byte[] keyfileBytes)
 {
     passwordBytes = Blake2.KeyedHash(passwordBytes, keyfileBytes);
     CryptographicOperations.ZeroMemory(keyfileBytes);
     return(passwordBytes);
 }
コード例 #10
0
ファイル: Keyfiles.cs プロジェクト: tej0402/Kryptor
 public static byte[] ReadKeyfile(string keyfilePath)
 {
     using var keyfile = new FileStream(keyfilePath, FileMode.Open, FileAccess.Read, FileShare.Read, Constants.FileStreamBufferSize, FileOptions.SequentialScan);
     return Blake2.Hash(keyfile);
 }
コード例 #11
0
ファイル: Generate.cs プロジェクト: smalltsky/Kryptor
 public static byte[] KeyEncryptionKey(byte[] ephemeralSharedSecret, byte[] salt)
 {
     byte[] keyEncryptionKey = Blake2.KeyDerivation(ephemeralSharedSecret, salt, Constants.EncryptionKeyLength);
     Utilities.ZeroArray(ephemeralSharedSecret);
     return(keyEncryptionKey);
 }
コード例 #12
0
ファイル: Generate.cs プロジェクト: tej0402/Kryptor
 public static byte[] KeyEncryptionKey(byte[] ephemeralSharedSecret, byte[] salt)
 {
     byte[] keyEncryptionKey = Blake2.KeyDerivation(ephemeralSharedSecret, salt, Constants.EncryptionKeyLength);
     CryptographicOperations.ZeroMemory(ephemeralSharedSecret);
     return(keyEncryptionKey);
 }