Esempio n. 1
0
        private static void ValidateSigningKey(byte[] keyAlgorithm)
        {
            bool validKey = Utilities.Compare(keyAlgorithm, Constants.Ed25519KeyHeader);

            if (!validKey)
            {
                throw new ArgumentException("Please specify an asymmetric signing key.");
            }
        }
Esempio n. 2
0
        public static void ValidateFormatVersion(byte[] formatVersion, byte[] currentFormatVersion)
        {
            bool validFormatVersion = Utilities.Compare(formatVersion, currentFormatVersion);

            if (!validFormatVersion)
            {
                throw new ArgumentException("Incorrect file format for this version of Kryptor.");
            }
        }
Esempio n. 3
0
        private static void ValidateKeyVersion(byte[] privateKey)
        {
            byte[] keyVersion      = GetKeyVersion(privateKey);
            bool   validKeyVersion = Utilities.Compare(keyVersion, Constants.PrivateKeyVersion);

            if (!validKeyVersion)
            {
                throw new ArgumentException("Unsupported private key version.");
            }
        }
Esempio n. 4
0
 private static void RetypeNewPassword(char[] password)
 {
     Console.WriteLine("Retype password:"******"Passwords do not match.");
         Environment.Exit(13);
     }
 }
Esempio n. 5
0
 public static bool?IsSignatureFile(string filePath)
 {
     try
     {
         byte[] magicBytes = ReadFileHeader(filePath, offset: 0, Constants.SignatureMagicBytes.Length);
         return(Utilities.Compare(magicBytes, Constants.SignatureMagicBytes));
     }
     catch (Exception ex) when(ExceptionFilters.FileAccess(ex))
     {
         return(null);
     }
 }
Esempio n. 6
0
 public static bool?IsKryptorFile(string filePath)
 {
     try
     {
         byte[] magicBytes = FileHeaders.ReadMagicBytes(filePath);
         return(Utilities.Compare(magicBytes, Constants.KryptorMagicBytes));
     }
     catch (Exception ex) when(ExceptionFilters.FileAccess(ex))
     {
         return(null);
     }
 }
Esempio n. 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);
        }