CryptoSys PKI Pro Manual

Rsa.MakeKeys(String, String, String, Int32, Rsa.PublicExponent, Rsa.PbeOptions, String, Rsa.Format, Boolean) Method

Generate an RSA public/private key pair.

Syntax

[C#]
public static int MakeKeys(
   string publicKeyFile,
   string privateKeyFile,
   string password,
   int bits,
   Rsa.PublicExponent exponent = Rsa.PublicExponent.Exp_EQ_65537,
   Rsa.PbeOptions pbes = Rsa.PbeOptions.Default,
   string paramString = "",
   Rsa.Format fileFormat = Rsa.Format.Default,
   bool showProgress = false 
)
[VB]
Public Shared Function MakeKeys (
   publicKeyFile As String,
   privateKeyFile As String,
   password As String,
   bits As Integer,
   Optional exponent As Rsa.PublicExponent = Rsa.PublicExponent.Exp_EQ_65537,
   Optional pbes As Rsa.PbeOptions = Rsa.PbeOptions.Default,
   Optional paramString As String = "",
   Optional fileFormat As Rsa.Format = Rsa.Format.Default,
   Optional showProgress As Boolean = false 
) As Integer

Parameters

publicKeyFile  String
Output filename for public key
privateKeyFile  String
Output filename for (encrypted) private key
password  String
Password for encrypted private key
bits  Int32
Required key modulus size in bits (min 96)
exponent  Rsa.PublicExponent  (Optional)
Exponent [default=65537=F4]
pbes  Rsa.PbeOptions  (Optional)
Encryption scheme to encrypt private key [default=pbeWithSHAAnd3-KeyTripleDES-CBC from PKCS#12]
paramString  String  (Optional)
Optional parameters. A set of attribute name=value pairs separated by a semicolon ";" (see remarks)
fileFormat  Rsa.Format  (Optional)
Format to save file [default = DER binary]
showProgress  Boolean  (Optional)
Indicate progress in console

Return Value

Int32
Zero if successful or non-zero error code

Remarks

Valid name-value pairs for paramString are:

ParameterDescription
count=integerTo set the iteration count used in the PBKDF2 method, e.g. "count=5000;" [default=2048].
prf=hmac-nameTo change the HMAC algorithm used in the PBKDF2 method, e.g. "prf=hmacwithSHA256;" [default=hmacwithSHA1].

Valid values for hmac-name are one of {hmacWithSHA1, hmacWithSHA224, hmacWithSHA256, hmacWithSHA384, hmacWithSHA512}.

Example

string pubkeyFile = "carol_pub.pem.txt";
string prikeyFile = "carol_epk.pem.txt";
int n = Rsa.MakeKeys(pubkeyFile, prikeyFile, "strong-password!", 2048, Rsa.PublicExponent.Exp_EQ_65537,
Rsa.PbeOptions.Pbe_Pbkdf2_aes128_CBC, "count=3000;prf=hmacWithSHA256", Rsa.Format.PEM, true);
Console.WriteLine("Rsa.MakeKeys returned {0}", n);
Debug.Assert(n == 0, "Failed to create RSA key pair");
Console.WriteLine("Created public/private key pair OK");

See Also

VB6/C equivalent: RSA_MakeKeysXtd

[Contents] [Index]

[PREV: Rsa.MakeKeys(String, String, Int32, Rsa.PublicExponent, Int32, String, Rsa.PbeOptions, Boolean, Byte) Method...]   [Contents]   [Index]   
   [NEXT: Rsa.PublicKeyFromPrivate Method...]

Copyright © 2004-26 D.I. Management Services Pty Ltd t/a CryptoSys. All rights reserved. Generated 2026-09-21T05:59:39Z.