CryptoSys PKI
23.0.0
|
RSA Encryption and Public Key Functions. More...
Public Types | |
enum class | AdvOpts |
Advanced options. More... | |
enum class | EME |
Encoding method for encryption. More... | |
enum class | Format |
Format for saved RSA key file. More... | |
enum class | HashAlg |
Hash function for OAEP encoding. More... | |
enum class | PbeScheme |
Password-based encryption scheme to encrypt the private key file. More... | |
enum class | PublicExponent |
Choice for public exponent (e). More... | |
enum | XmlOptions : unsigned int |
Options when converting between internal RSA key and XML. More... | |
Static Public Member Functions | |
static bvec_t | DecodeMsgForEncryption (const bvec_t &data, EME method=EME::PKCSv1_5) |
Decode a message for encryption. More... | |
static bvec_t | DecodeMsgForSignature (const bvec_t &data, bool getFullDigestInfo=false) |
Extract digest (or digestinfo) from an EMSA-PKCS1-v1_5-encoded block. More... | |
static bvec_t | Decrypt (const bvec_t &data, const std::string &privateKeyFileOrString, const std::string &password="", EME method=EME::PKCSv1_5, HashAlg hashAlg=HashAlg::Sha1, AdvOpts advOpts=AdvOpts::Default) |
Decrypt a message encrypted using an RSA encryption scheme. More... | |
static bvec_t | EncodeMsgForEncryption (int blockBytes, const bvec_t &message, EME method=EME::PKCSv1_5) |
Encode a message for encryption. More... | |
static bvec_t | EncodeMsgForSignature (int blockBytes, const bvec_t &message, HashAlg hashAlg=HashAlg::Sha1, bool digestOnly=false) |
Encode a message for signature. More... | |
static bvec_t | Encrypt (const bvec_t &data, const std::string &publicKeyFileOrString, EME method=EME::PKCSv1_5, HashAlg hashAlg=HashAlg::Sha1, AdvOpts advOpts=AdvOpts::Default, const std::string ¶ms="") |
Encrypt a short message using RSA encryption. More... | |
static std::string | FromXMLString (const std::string &xmlstr, XmlOptions opts=XmlOptions::None) |
Return an RSA key string in internal format from an XML string. More... | |
static int | GetPrivateKeyFromPFX (const std::string &outputFile, const std::string &pfxFile) |
Extract an encrypted private key from a PKCS-12 PKCS8ShroudedKeyBag, saving the output directly as a new file. More... | |
static int | KeyBits (const std::string &keyStr) |
Get number of significant bits in RSA key modulus. More... | |
static int | KeyBytes (const std::string &keyStr) |
Get number of bytes (octets) in RSA key modulus. More... | |
static uint32_t | KeyHashCode (const std::string &intKeyString) |
Compute the hash code of an "internal" RSA public or private key string. More... | |
static bool | KeyIsPrivate (const std::string &keyStr) |
Determine if keystring is a private key. More... | |
static bool | KeyMatch (const std::string &priKeyStr, const std::string &pubKeyStr) |
Determine if a pair of "internal" RSA private and public key strings are matched. More... | |
static std::string | KeyValue (const std::string &keyStr, const std::string &fieldName) |
Extract a base64-encoded RSA key value from internal key string. More... | |
static int | MakeKeys (const std::string &publicKeyFile, const std::string &privateKeyFile, const std::string &password, int nbits, PublicExponent exponent=PublicExponent::Exp_EQ_65537, PbeScheme pbes=PbeScheme::Default, const std::string ¶mString="", Format fileFormat=Format::Binary, bool showProgress=false) |
Generate an RSA public/private key pair and save as two key files. More... | |
static std::string | PublicKeyFromPrivate (const std::string &keyStr) |
Get internal RSA public key string from an internal RSA private key string. More... | |
static bvec_t | RawPrivate (const bvec_t &data, const std::string &keyStr) |
Transforms (that is, encrypts or decrypts) raw data using an RSA private key. More... | |
static bvec_t | RawPublic (const bvec_t &data, const std::string &keyStr) |
Transforms (that is, encrypts or decrypts) raw data using an RSA public key. More... | |
static std::string | ReadPrivateKey (const std::string &keyFileOrString, const std::string &password="") |
Read from a file or string containing a private key into an "internal" key string. More... | |
static std::string | ReadPublicKey (const std::string &keyFileOrString) |
Read from a file or string containing a public key into an "internal" key string. More... | |
static int | SaveEncKey (const std::string &outputFile, const std::string &keyStr, const std::string &password, PbeScheme pbes=PbeScheme::Default, const std::string ¶mString="", Format fileFormat=Format::Binary) |
Save an internal RSA key string to an encrypted key file. More... | |
static int | SaveKey (const std::string &outputFile, const std::string &keyStr, Format fileFormat=Format::Binary) |
Save an internal RSA key string to a key file. More... | |
static std::string | ToXMLString (const std::string &keyStr, XmlOptions opts=XmlOptions::None, const std::string &prefix="") |
Return an XML string representation of an RSA internal key string. More... | |
RSA Encryption and Public Key Functions.
|
strong |
Advanced options.
Enumerator | |
---|---|
Default | Default options. |
Mgf1_Sha1 | Force the MGF hash function to be SHA-1 (OAEP only, default = same as encoding set by Rsa::HashAlg) |
|
strong |
|
strong |
|
strong |
|
strong |
Password-based encryption scheme to encrypt the private key file.
|
strong |
Choice for public exponent (e).
enum dipki::Rsa::XmlOptions : unsigned int |
Options when converting between internal RSA key and XML.
|
static |
Decode a message for encryption.
data | Encoded block. |
method | Encoding method to use [default = EME-PKCS1-v1_5] |
|
static |
Extract digest (or digestinfo) from an EMSA-PKCS1-v1_5-encoded block.
data | Encoded message for signature. |
getFullDigestInfo | If true, extract the full DigestInfo ; otherwise just extract the message digest itself. |
|
static |
Decrypt a message encrypted using an RSA encryption scheme.
data | Data to be decrypted (must be exactly the same length as the key modulus size). |
privateKeyFileOrString | Name of the private key file, or a string containing the key in PEM format, or a valid internal private key string. |
password | Password for encrypted private key, or "" if password is not required. |
method | Encoding method to use [default=EME-PKCS1-v1_5] |
hashAlg | Hash function for EME-OAEP encoding, otherwise ignored [default=SHA-1]. |
advOpts | Advanced options for EME-OEAP only. |
|
static |
Encode a message for encryption.
blockBytes | Number of bytes in the output block. |
message | Message to be encoded. |
method | Encoding method to use [default = EME-PKCS1-v1_5] |
|
static |
Encode a message for signature.
blockBytes | Number of bytes in the output block. |
message | Message to be encoded. |
hashAlg | Message digest algorithm to use [default=SHA-1 – CAUTION!] |
digestOnly | Set true to pass the message digest value instead of the message itself. |
|
static |
Encrypt a short message using RSA encryption.
data | Data to be encrypted (must be at least 11 bytes shorter than the key modulus size). |
publicKeyFileOrString | Name of the public key file or X.509 certificate, or a string containing the key or certificate in PEM format, or a valid internal public key string. |
method | Encoding method to use [default=EME-PKCS1-v1_5] |
hashAlg | Hash function for EME-OAEP encoding, otherwise ignored [default=SHA-1]. |
advOpts | Advanced options for EME-OEAP only. |
params | For specialist use. |
|
static |
Return an RSA key string in internal format from an XML string.
xmlstr | The XML string to use to reconstruct the RSA key. |
opts | Option flags |
std::runtime_error | Exception with error code if XML string is invalid. |
|
static |
Extract an encrypted private key from a PKCS-12 PKCS8ShroudedKeyBag, saving the output directly as a new file.
outputFile | Name of output file to be created. |
pfxFile | Name of PFX (.p12) file. |
pkcs-12-pkcs-8ShroudedKeyBag
found in the PFX file will be extracted and saved directly as a BER-encoded EncryptedPrivateKeyInfo
file. No decryption or other conversion is carried out. std::runtime_error | Exception with error code if pfxFile is invalid or if output file cannot be created. |
|
static |
Get number of significant bits in RSA key modulus.
keyStr | Internal key string (private or public). |
|
static |
Get number of bytes (octets) in RSA key modulus.
keyStr | Internal key string (private or public). |
|
static |
Compute the hash code of an "internal" RSA public or private key string.
intKeyString | Key as an internal key string. |
|
static |
Determine if keystring is a private key.
keyStr | Internal key string (private or public). |
true
if the key string contains a valid RSA private key, or false
if a valid RSA public key. std::runtime_error | Exception with error code if internal key string is invalid. |
|
static |
Determine if a pair of "internal" RSA private and public key strings are matched.
priKeyStr | Internal RSA private key string. |
pubKeyStr | Internal RSA public key string. |
true
if the keystrings are valid and matched, or false
if the keystrings are valid but not matched. std::runtime_error | Exception with error code if an internal key string is invalid. |
|
static |
Extract a base64-encoded RSA key value from internal key string.
keyStr | Internal key string (private or public). |
fieldName | Name of field to be extracted: Modulus or Exponent . |
|
static |
Generate an RSA public/private key pair and save as two key files.
publicKeyFile | Output filename for public key. |
privateKeyFile | Output filename for (encrypted) private key. |
password | Password for encrypted private key (required). |
nbits | Required key modulus size in bits (min 96). |
exponent | Exponent [default=65537=F4] |
pbes | Encryption scheme to encrypt private key [default=pbeWithSHAAnd3-KeyTripleDES-CBC from PKCS#12] |
paramString | Optional parameters. A set of attribute name=value pairs separated by a semicolon ";" (see remarks). |
fileFormat | Format to save file [default = DER binary]. |
showProgress | Indicate progress in console. |
paramString
are: Parameter | Result |
---|---|
count=integer | To set the iteration count used in the PBKDF2 method, e.g. "count=5000;" [default=2048]. |
prf=hmac-name | To change the HMAC algorithm used in the PBKDF2 method, e.g. "prf=hmacWithSHA256;" [default=hmacWithSHA1 ]. |
rngseed=string | To add some user-supplied entropy for the key generation process, e.g. "rngseed=pqrrr1234xyz;" . |
{hmacWithSHA1,hmacWithSHA224,hmacWithSHA256,hmacWithSHA384,hmacWithSHA512}
.
|
static |
Get internal RSA public key string from an internal RSA private key string.
keyStr | Private key in "internal" format. |
std::runtime_error | Exception with error code if key string is invalid. |
Transforms (that is, encrypts or decrypts) raw data using an RSA private key.
data | Data to be transformed (must be same byte length as key modulus). |
keyStr | Private key in internal string format. |
Transforms (that is, encrypts or decrypts) raw data using an RSA public key.
data | Data to be transformed (must be same byte length as key modulus). |
keyStr | Public key in internal string format. |
|
static |
Read from a file or string containing a private key into an "internal" key string.
keyFileOrString | Name of private key file or a PEM String containing the key. |
password | Password for private key, if encrypted. |
|
static |
Read from a file or string containing a public key into an "internal" key string.
keyFileOrString | Name of X.509 certificate or public key file or a PEM String containing the key. |
|
static |
Save an internal RSA key string to an encrypted key file.
outputFile | Name of output file to be created. |
keyStr | The private RSA key as an internal key string. |
password | Password to be used for the encrypted key file. |
pbes | Encryption scheme to encrypt private key [default=pbeWithSHAAnd3-KeyTripleDES-CBC from PKCS#12] |
paramString | Optional parameters. A set of attribute name=value pairs separated by a semicolon ";" (see remarks). |
fileFormat | File format [default = binary]. |
paramString
are: Parameter | Result |
---|---|
count=integer | To set the iteration count used in the PBKDF2 method, e.g. "count=5000;" [default=2048]. |
prf=hmac-name | To change the HMAC algorithm used in the PBKDF2 method, e.g. "prf=hmacWithSHA256;" [default=hmacWithSHA1 ]. |
{hmacWithSHA1,hmacWithSHA224,hmacWithSHA256,hmacWithSHA384,hmacWithSHA512}
. std::runtime_error | Exception with error code if keyStr is invalid or if output file cannot be created. |
|
static |
Save an internal RSA key string to a key file.
outputFile | Name of output file to be created. |
keyStr | Key string (public or private) in internal format. |
fileFormat | File format [default = binary]. |
std::runtime_error | Exception with error code if keyStr is invalid or if output file cannot be created. |
|
static |
Return an XML string representation of an RSA internal key string.
keyStr | Internal key string (private or public). |
opts | Option flags |
prefix | Prefix to add to elements, e.g. "ds" or "ds:" . |
std::runtime_error | Exception with error code if internal key string is invalid. |