/// <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"); IAsymmetric Found = AsymmetricAlgorithms.FirstOrDefault(); if (Found == null) { throw new ArgumentException("No asymmetric encryption algorithm found"); } return(Found.CreateKey(PrivatePublic)); }
/// <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"); IAsymmetric 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"); IAsymmetric 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"); IAsymmetric Found = AsymmetricAlgorithms.FirstOrDefault(); if (Found == null) { throw new ArgumentException("No asymmetric encryption algorithm found"); } return(Found.Encrypt(Input, Key)); }
public DataRevController( IConfiguration configuration, IAsymmetric asymmetric, ISymmetric symmetric, V2RayDbContent db) { this.configuration = configuration; this.symmetric = symmetric; this.asymmetric = asymmetric; this.db = db; string key = configuration.GetValue <string>("KeyFile"); using (TextReader reader = System.IO.File.OpenText(key)) { PemReader pem = new PemReader(reader); AsymmetricCipherKeyPair pair = (AsymmetricCipherKeyPair)pem.ReadObject(); this.key = pair.Private; } }
public TimeBasedService( IV2RayCollectService v2ray, IAsymmetric asymmetric, ISymmetric symmetric, IHttpClientFactory factory, IConfiguration configuration) { this.v2rayService = v2ray; this.http = factory.CreateClient(); this.asymmetric = asymmetric; this.symmetric = symmetric; string path = configuration.GetValue <string>("PublicKey"); using (TextReader reader = File.OpenText(path)) { PemReader pem = new PemReader(reader); var pemObject = pem.ReadObject(); this.parameter = pemObject as AsymmetricKeyParameter; } http.BaseAddress = new Uri(configuration.GetConnectionString("DataServer")); }