internal static KeyParameters RegistrateKeyParameters(this IConfiguration configuration) { var keyParametersD = configuration.GetSection("KeyParameters:D").Value; var keyParametersDP = configuration.GetSection("KeyParameters:DP").Value; var keyParametersDQ = configuration.GetSection("KeyParameters:DQ").Value; var keyParametersExponent = configuration.GetSection("KeyParameters:Exponent").Value; var keyParametersInverseQ = configuration.GetSection("KeyParameters:InverseQ").Value; var keyParametersModulus = configuration.GetSection("KeyParameters:Modulus").Value; var keyParametersP = configuration.GetSection("KeyParameters:P").Value; var keyParametersQ = configuration.GetSection("KeyParameters:Q").Value; var keyParameters = new KeyParameters { D = keyParametersD, DP = keyParametersDP, DQ = keyParametersDQ, Exponent = keyParametersExponent, InverseQ = keyParametersInverseQ, Modulus = keyParametersModulus, P = keyParametersP, Q = keyParametersQ }; return(keyParameters); }
/// <summary> /// Initializes a new instance of the <see cref="RsaGenerationRequest"/> class. /// Use to request a new RSA Credential /// </summary> /// <param name="credentialName">Name of credential</param> /// <param name="keyLength">Optional Key Length (default: 2048)</param> /// <param name="overwriteMode">Overwrite existing credential (default: no-overwrite)</param> public RsaGenerationRequest(string credentialName, CertificateKeyLength keyLength = CertificateKeyLength.Length_2048, OverwiteMode overwriteMode = OverwiteMode.converge) { Name = credentialName; Type = CredentialType.RSA; Parameters = new KeyParameters { KeyLength = keyLength }; Mode = overwriteMode; }
/// <summary> /// Initializes a new instance of the <see cref="RsaGenerationRequest"/> class. /// Use to request a new RSA Credential /// </summary> /// <param name="credentialName">Name of credential</param> /// <param name="keyLength">Optional Key Length (default: 2048)</param> /// <param name="overwrite">Overwrite existing credential (default: false)</param> public RsaGenerationRequest(string credentialName, CertificateKeyLength keyLength = CertificateKeyLength.Length_2048, bool overwrite = false) { Name = credentialName; Type = CredentialType.RSA; Parameters = new KeyParameters { KeyLength = keyLength }; Overwrite = overwrite; }
private static void CreatePgpKeyForAlice(IKeyGenerator keygen) { KeyParameters aliceparam = new KeyParameters { RealName = "Alice", Comment = "my comment", Email = "*****@*****.**", ExpirationDate = DateTime.Now.AddYears(3), KeyLength = KeyParameters.KEY_LENGTH_2048, // primary key parameters PubkeyAlgorithm = KeyAlgorithm.RSA, // the primary key algorithm MUST have the "Sign" capability PubkeyUsage = AlgorithmCapability.CanSign | AlgorithmCapability.CanAuth | AlgorithmCapability.CanCert, // subkey parameters (optional) SubkeyLength = KeyParameters.KEY_LENGTH_4096, SubkeyAlgorithm = KeyAlgorithm.RSA, SubkeyUsage = AlgorithmCapability.CanEncrypt, Passphrase = "topsecret" }; Console.WriteLine( @"Create a new PGP key for Alice. Name: {0} Comment: {1} Email: {2} Secret passphrase: {3} Expire date: {4} Primary key algorithm = {5} ({6} bit) Sub key algorithm = {7} ({8} bit)", aliceparam.RealName, aliceparam.Comment, aliceparam.Email, aliceparam.Passphrase, aliceparam.ExpirationDate.ToString(CultureInfo.InvariantCulture), Gpgme.GetPubkeyAlgoName(aliceparam.PubkeyAlgorithm), aliceparam.PubkeyLength, Gpgme.GetPubkeyAlgoName(aliceparam.SubkeyAlgorithm), aliceparam.SubkeyLength); Console.Write("Start key generation.. "); GenkeyResult result = keygen.GenerateKey( Protocol.OpenPGP, aliceparam); Console.WriteLine("done.\nFingerprint: {0}\n", result.Fingerprint); }
private static void CreatePgpKeyForBob(IKeyGenerator keygen) { Console.Write("Create PGP key for Bob.. "); KeyParameters bobparam = new KeyParameters { RealName = "Bob", Email = "*****@*****.**", ExpirationDate = DateTime.Now.AddYears(2), Passphrase = "topsecret" }; GenkeyResult result = keygen.GenerateKey( Protocol.OpenPGP, bobparam); Console.WriteLine("done.\nFingerprint: {0}\n", result.Fingerprint); }
public async Task <KeyResult> FetchKeystore() { // prepare keys endpoint request payload var payload = new KeyParameters() { encryptionType = "WebCryptoAPI" }; // prepare HTTP headers to make server2flex rest call var signature = GenerateSignature(); byte[] buffer = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload)); // TODO this should probably be rewritten to use the newer HttpClient from .net 4.5 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(flexKeysEndpoint); request.Method = signature["HTTP-Verb"]; request.Headers.Add("X-MERCHANT-ID", mid); request.Headers.Add("Authorization", signature["Authorization"]); request.Headers.Add("HTTP-Verb", signature["HTTP-Verb"]); request.Headers.Add("Organization-Id", signature["Organization-Id"]); request.Headers.Add("Time", signature["Time"]); request.Headers.Add("CMM-Key", signature["CMM-Key"]); request.ContentType = signature["Content-Type"]; request.ContentLength = buffer.Length; var reqStream = request.GetRequestStream(); reqStream.Write(buffer, 0, buffer.Length); reqStream.Close(); using (var response = (HttpWebResponse)request.GetResponse()) { var encoding = Encoding.UTF8; using (var responseStream = response.GetResponseStream()) using (var reader = new StreamReader(responseStream, encoding)) { var result = reader.ReadToEnd(); return(await Task.Factory.StartNew(() => { return JsonConvert.DeserializeObject <KeyResult>(result); })); } } }
private static void CreatePgpKeyForMallory(IKeyGenerator keygen) { Console.Write("Create PGP key for Mallory.. "); KeyParameters malloryparam = new KeyParameters { RealName = "Mallory", Email = "*****@*****.**" }; malloryparam.MakeInfinitely(); // PGP key does not expire malloryparam.Passphrase = "topsecret"; GenkeyResult result = keygen.GenerateKey( Protocol.OpenPGP, malloryparam); Console.WriteLine("done.\nFingerprint: {0}", result.Fingerprint); }
static void Main(string[] args) { Console.WriteLine("This example will create PGP keys in your default keyring.\n"); // First step is to create a context Context ctx = new Context(); EngineInfo info = ctx.EngineInfo; if (info.Protocol != Protocol.OpenPGP) { ctx.SetEngineInfo(Protocol.OpenPGP, null, null); info = ctx.EngineInfo; } Console.WriteLine("GnuPG home directory: {0}\n" + "Version: {1}\n" + "Reqversion: {2} \n" + "Program: {3}\n", info.HomeDir, info.Version, info.ReqVersion, info.FileName); IKeyGenerator keygen = ctx.KeyStore; KeyParameters aliceparam, bobparam, malloryparam; aliceparam = new KeyParameters(); aliceparam.RealName = "Alice"; aliceparam.Comment = "my comment"; aliceparam.Email = "*****@*****.**"; aliceparam.ExpirationDate = DateTime.Now.AddYears(3); // primary key parameters aliceparam.KeyLength = KeyParameters.KEY_LENGTH_2048; aliceparam.PubkeyAlgorithm = KeyAlgorithm.RSA; // the primary key algorithm MUST have the "Sign" capability aliceparam.PubkeyUsage = AlgorithmCapability.CanSign | AlgorithmCapability.CanAuth | AlgorithmCapability.CanCert; // subkey parameters (optional) aliceparam.SubkeyLength = KeyParameters.KEY_LENGTH_4096; aliceparam.SubkeyAlgorithm = KeyAlgorithm.RSA; aliceparam.SubkeyUsage = AlgorithmCapability.CanEncrypt; aliceparam.Passphrase = "topsecret"; // Generate Alice key Console.WriteLine( "Create a new PGP key for Alice.\n" + "Name: {0}\n" + "Comment: {1} \n" + "Email: {2} \n" + "Secret passphrase: {3} \n" + "Expire date: {4} \n" + "Primary key algorithm = {5} ({6} bit)\n" + "Sub key algorithm = {7} ({8} bit)", aliceparam.RealName, aliceparam.Comment, aliceparam.Email, aliceparam.Passphrase, aliceparam.ExpirationDate.ToString(), Gpgme.GetPubkeyAlgoName(aliceparam.PubkeyAlgorithm), aliceparam.PubkeyLength, Gpgme.GetPubkeyAlgoName(aliceparam.SubkeyAlgorithm), aliceparam.SubkeyLength ); Console.Write("Start key generation.. "); GenkeyResult result = keygen.GenerateKey( Protocol.OpenPGP, aliceparam); Console.WriteLine("done.\nFingerprint: {0}\n", result.Fingerprint); // okay, create two more keys Console.Write("Create PGP key for Bob.. "); bobparam = new KeyParameters(); bobparam.RealName = "Bob"; bobparam.Email = "*****@*****.**"; bobparam.ExpirationDate = DateTime.Now.AddYears(2); bobparam.Passphrase = "topsecret"; result = keygen.GenerateKey( Protocol.OpenPGP, bobparam); Console.WriteLine("done.\nFingerprint: {0}\n", result.Fingerprint); Console.Write("Create PGP key for Mallory.. "); malloryparam = new KeyParameters(); malloryparam.RealName = "Mallory"; malloryparam.Email = "*****@*****.**"; malloryparam.MakeInfinitely(); // PGP key does not expire malloryparam.Passphrase = "topsecret"; result = keygen.GenerateKey( Protocol.OpenPGP, malloryparam); Console.WriteLine("done.\nFingerprint: {0}", result.Fingerprint); return; }