private static void ValidateSigningKey(byte[] keyAlgorithm) { bool validKey = Utilities.Compare(keyAlgorithm, Constants.Ed25519KeyHeader); if (!validKey) { throw new ArgumentException("Please specify an asymmetric signing key."); } }
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."); } }
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."); } }
private static void RetypeNewPassword(char[] password) { Console.WriteLine("Retype password:"******"Passwords do not match."); Environment.Exit(13); } }
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); } }
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); } }
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); }