/// <summary> /// String info for the manager /// </summary> /// <returns>The string info that the manager contains</returns> public override string ToString() { var Builder = new StringBuilder(); Builder.AppendLineFormat("Asymmetric algorithms: {0}", AsymmetricAlgorithms.ToString(x => x.Name)); Builder.AppendLineFormat("Hashing algorithms: {0}", HasherAlgorithms.ToString(x => x.Name)); Builder.AppendLineFormat("Shift algorithms: {0}", ShiftAlgorithms.ToString(x => x.Name)); Builder.AppendLineFormat("Symmetric algorithms: {0}", SymmetricAlgorithms.ToString(x => x.Name)); return(Builder.ToString()); }
/// <summary> /// Verifies a signed hash against the unsigned version /// </summary> /// <param name="Hash">The unsigned hash (should be 64bit string)</param> /// <param name="SignedHash">The signed hash (should be 64bit string)</param> /// <param name="Key">The key to use in decryption</param> /// <returns>True if it is verified, false otherwise</returns> public bool VerifyHash(string Hash, string SignedHash, string Key) { Contract.Requires <NullReferenceException>(AsymmetricAlgorithms != null, "AsymmetricAlgorithms"); var Found = AsymmetricAlgorithms.FirstOrDefault(); if (Found == null) { throw new ArgumentException("No asymmetric encryption algorithm found"); } return(Found.VerifyHash(Hash, SignedHash, Key)); }
/// <summary> /// Takes a string and creates a signed hash of it /// </summary> /// <param name="Input">Input string</param> /// <param name="Key">Key to encrypt/sign with</param> /// <param name="Hash">This will be filled with the unsigned hash</param> /// <param name="EncodingUsing">Encoding that the input is using (defaults to UTF8)</param> /// <returns>A signed hash of the input (64bit string)</returns> public string SignHash(string Input, string Key, out string Hash, Encoding EncodingUsing = null) { Contract.Requires <NullReferenceException>(AsymmetricAlgorithms != null, "AsymmetricAlgorithms"); var Found = AsymmetricAlgorithms.FirstOrDefault(); if (Found == null) { throw new ArgumentException("No asymmetric encryption algorithm found"); } return(Found.SignHash(Input, Key, out Hash, EncodingUsing)); }
/// <summary> /// Encrypts a string using RSA /// </summary> /// <param name="Input"> /// Input byte array (should be small as anything over 128 bytes can not be decrypted) /// </param> /// <param name="Key">Key to use for encryption</param> /// <returns>An encrypted byte array (64bit string)</returns> public byte[] Encrypt(byte[] Input, string Key) { Contract.Requires <NullReferenceException>(AsymmetricAlgorithms != null, "AsymmetricAlgorithms"); var Found = AsymmetricAlgorithms.FirstOrDefault(); if (Found == null) { throw new ArgumentException("No asymmetric encryption algorithm found"); } return(Found.Encrypt(Input, Key)); }
/// <summary> /// Creates a new set of keys /// </summary> /// <param name="PrivatePublic">True if private key should be included, false otherwise</param> /// <returns>XML representation of the key information</returns> public string CreateKey(bool PrivatePublic) { Contract.Requires <NullReferenceException>(AsymmetricAlgorithms != null, "AsymmetricAlgorithms"); var Found = AsymmetricAlgorithms.FirstOrDefault(); if (Found == null) { throw new ArgumentException("No asymmetric encryption algorithm found"); } return(Found.CreateKey(PrivatePublic)); }
public static (string, string, AsymmetricAlgorithms) ReadArgs(string[] args) { if (args.Length == 1 && (args[0] == "-h" || args[0] == "-help")) { Console.WriteLine("arg 1 = dnsName"); Console.WriteLine("arg 2 = password"); Console.WriteLine("arg 3 (optional) = RSA|ECDSA"); return(null, null, AsymmetricAlgorithms.ECDSA); } else if (args.Length < 2) { throw new InvalidOperationException("Invalid arguments"); } else { string dnsName = args[0]; string password = args[1]; AsymmetricAlgorithms algorithm = AsymmetricAlgorithms.ECDSA; if (args.Length == 3) { switch (args[2].ToLower()) { case "rsa": algorithm = AsymmetricAlgorithms.RSA; break; } } if (!string.IsNullOrWhiteSpace(password) && !string.IsNullOrWhiteSpace(dnsName)) { return(password, dnsName, algorithm); } else { throw new InvalidOperationException("Invalid arguments"); } } }