/// <summary> /// Creates a key pair in the key store. /// </summary> /// <param name="keySize">Size for key. Valid values from 1024 to 4096.</param> /// <param name="userId">User id for the key.</param> /// <param name="keyAlgorithm">Algorithm used for key storage.</param> /// <param name="password">Private key password.</param> /// <param name="compressionTypes">Types of compression supported in comma delimited format.</param> /// <param name="hashingAlgorithmTypes">Types of hashing supported in comma delimited format.</param> /// <param name="cypherTypes">Types of cyphers supported in comma delimited format.</param> /// <param name="expirationDate">Date at which the key will no longer be valid.</param> /// <returns>Returns object with PGP Key information.</returns> public PGPKeyInformation CreateKey(int keySize, string userId, string keyAlgorithm, string password, string compressionTypes, string hashingAlgorithmTypes, string cypherTypes, DateTime expirationDate) { KeyPairInformation kpi = null; if (IsValidKeySize(keySize) == false) { _msg.Length = 0; _msg.Append("Invalid key size: "); _msg.Append(keySize.ToString()); _msg.Append(" Valid key sizes: Min: "); _msg.Append(_minValidKeySize.ToString()); _msg.Append(", Max: "); _msg.Append(_maxValidKeySize.ToString()); _msg.Append("."); throw new System.Exception(_msg.ToString()); } if (expirationDate == DateTime.MinValue || expirationDate == DateTime.MaxValue) { kpi = _keyStore.GenerateKeyPair(keySize, userId, ConvertToKeyAlgorithm(keyAlgorithm), password, ConvertToCompressionAlgorithmArray(compressionTypes), ConvertToHashAlgorithmArray(hashingAlgorithmTypes), ConvertToCypherAlgorithmArray(cypherTypes)); } else { kpi = _keyStore.GenerateKeyPair(keySize, userId, ConvertToKeyAlgorithm(keyAlgorithm), password, ConvertToCompressionAlgorithmArray(compressionTypes), ConvertToHashAlgorithmArray(hashingAlgorithmTypes), ConvertToCypherAlgorithmArray(cypherTypes), expirationDate); } GetKeyList(); return(ConvertKeyPairInformation(kpi)); }
public void CreateSignature(string privateKeyPassword, string userId, int ID) { string path = System.Web.HttpContext.Current.Server.MapPath("../PageStudents/Sig") + "/" + "key.store"; KeyStore ks = new KeyStore(@path, "changeit"); // userId = "*****@*****.**"; // privateKeyPassword = "******"; HashAlgorithm[] hashing = { HashAlgorithm.SHA1, HashAlgorithm.MD5, HashAlgorithm.SHA256, HashAlgorithm.SHA384, HashAlgorithm.SHA512 }; CompressionAlgorithm[] compression = { CompressionAlgorithm.ZIP, CompressionAlgorithm.ZLIB, CompressionAlgorithm.UNCOMPRESSED }; CypherAlgorithm[] cypher = { CypherAlgorithm.CAST5, CypherAlgorithm.AES_128, CypherAlgorithm.AES_192, CypherAlgorithm.AES_256, CypherAlgorithm.BLOWFISH }; ks.GenerateKeyPair(2048, userId, KeyAlgorithm.RSA, privateKeyPassword, compression, hashing, cypher); ExportDemo(path, userId, ID); }
public static void CreateSignature(string privateKeyPassword, string userId, int ID) { string path = "C:/Users/Dua'a-Orcas/Desktop/WebApplication1/WebApplication1/WebApplication1/PageStudents/Sig/key.store"; KeyStore ks = new KeyStore(@path, "changeit"); // userId = "*****@*****.**"; // privateKeyPassword = "******"; HashAlgorithm[] hashing = { HashAlgorithm.SHA1, HashAlgorithm.MD5, HashAlgorithm.SHA256, HashAlgorithm.SHA384, HashAlgorithm.SHA512 }; CompressionAlgorithm[] compression = { CompressionAlgorithm.ZIP, CompressionAlgorithm.ZLIB, CompressionAlgorithm.UNCOMPRESSED }; CypherAlgorithm[] cypher = { CypherAlgorithm.CAST5, CypherAlgorithm.AES_128, CypherAlgorithm.AES_192, CypherAlgorithm.AES_256, CypherAlgorithm.BLOWFISH }; ks.GenerateKeyPair(2048, userId, KeyAlgorithm.RSA, privateKeyPassword, compression, hashing, cypher); ExportDemo(path, userId, ID); }