A .NET interface to CryptoSys PKI.
Class | Description |
---|---|
Asn1 | ASN.1 utilities |
Cipher | Generic Block Cipher |
Cms | Create, read and analyze Cryptographic Message Syntax (CMS) objects. |
Cnv | Character conversion routines |
Compr | Compression utilities |
Ecc | Elliptic curve cryptography |
General | General info about the core DLL and errors returned by it. |
Hash | Message Digest Hash Functions |
HexExtension | Extension methods for hex conversion |
Hmac | Keyed-hash based message authentication code (HMAC) functions |
Hpke | Hybrid Public Key Encryption functions (HPKE) |
Kdf | Key derivation functions (KDF) |
Ocsp | Online Certificate Status Protocol (OCSP) |
Pbe | Password-based encryption |
Pem | PEM file conversion routines |
Pfx | PKCS-12 (PFX) File Functions |
Prf | Pseudorandom function (PRF) methods. |
Pwd | Password Dialog Functions |
Rng | Random Number Generator to NIST SP800-90 |
Rsa | RSA Encryption and Public Key Functions |
Sig | Signature creation and verification |
Smime | S/MIME utilities |
Tdea | Triple DES Cipher (3DES, TDEA) [deprecated: use Cipher() class with CipherAlgorithm.Tdea instead] |
Wipe | Data Wiping Functions |
X509 | X.509 Certificate Functions |
Xof | Extendable-output function (XOF) methods. |
Enumeration | Description |
---|---|
AeadAlgorithm | Authenticated encryption algorithm. |
Asn1.Options | Options for ASN.1 methods |
Cipher.Opts | Advanced options |
CipherAlgorithm | Block Cipher Algorithm |
Cms.ComprDataOptions | Advanced options for CMS compressed-data objects |
Cms.ContentEncrAlg | Content encryption algorithm. |
Cms.EnvDataOptions | Advanced options for CMS enveloped-data objects. |
Cms.Format | Output format. |
Cms.KeyEncrAlgorithm | Key encryption algorithm. |
Cms.ReadOptions | Options for reading CMS objects. |
Cms.SigAlg | Signature algorithm for CMS signed-data objects. |
Cms.SigDataOptions | Advanced options for CMS signed-data objects |
Cnv.EncodingConversion | Conversion directions for ByteEncoding. |
Cnv.EndianNess | Byte order. |
Ecc.CurveName | Supported curve names. |
Ecc.Format | Format for output files. |
Ecc.KeyType | Key type for unencrypted key file. |
Ecc.PbeScheme | Password-based encryption scheme to encrypt the private key file. |
EncodingBase | Base for encoding methods |
HashAlgorithm | Message Digest Hash Algorithm |
Hpke.AeadAlg | AEAD functions supported for HPKE |
Hpke.CurveName | Supported ECDH curves for HPKE |
Hpke.OutputOpts | Options to format or re-encode output. |
Kdf.HashAlg | Hash algorithms for KDF |
Kdf.KdfAlg | Key derivation functions |
Kdf.KeyWrapAlg | Key wrap algorithms for KDF |
Mode | Cipher Mode |
Padding | Block Cipher Padding |
Pfx.Options | Specialist options. |
Prf.Alg | Pseudorandom function (PRF) algorithm. |
Rng.Options | Rng options |
Rng.Strength | Required security strength for user-prompted entropy |
Rsa.AdvOptions | Advanced options. |
Rsa.EME | Encoding method for encryption. |
Rsa.Format | Format for saved RSA key. |
Rsa.HashAlg | Hash function for OAEP encoding. |
Rsa.PbeOptions | Password-based encryption scheme to be used to encrypt the private key file. |
Rsa.PublicExponent | Choices for public exponent (e) |
Rsa.XmlOptions | Options when converting between internal RSA key and XML. |
Sig.Encoding | Encodings for signature output. |
Sig.SigOptions | Specialist options for signatures. |
Sig.VerifyOpts | Specialist options for verifying a signature. |
SigAlgorithm | Signature algorithm |
Smime.Options | Options for S/MIME methods |
Wipe.Options | Wipe options. |
X509.CertOptions | Options to create X.509 certificate. |
X509.CrlOptions | Options to create Certificate Revocation List (CRL) |
X509.CsrOptions | Options to create PKCS#10 certificate signing request (CSR) |
X509.KeyUsageOptions | Options for key usage in certificate |
X509.OutputOpts | Options to format or re-encode output. |
Xof.Alg | eXtendable-Output Function (XOF) algorithm. |
ASN.1 utilities
System.Object
CryptoSysPKI.Asn1
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Asn1
The Asn1 type exposes the following members.
Name | Description |
---|---|
TextDump | Dump details of an ASN.1 formatted data file to a text file. |
TextDumpToString | Dump details of ASN.1 formatted data to a string. |
Type | Describe the type of ASN.1 data. |
Dump details of an ASN.1 formatted data file to a text file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int TextDump(
string outputFile,
string fileOrPEMString,
.Options options = Asn1.Options.Default
Asn1)
Filename of text file to be created
Filename of ASN.1 formatted data file to be analyzed (or a string containing its base64 or PEM representation)
Option flags (optional)
Int32
Zero if successful; otherwise it returns an error code
Asn1 Class
CryptoSysPKI Namespace
Return a description of an error code.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string ErrorLookup(
int errCode
)
Code number
String
Corresponding error message
General Class
CryptoSysPKI Namespace
Dump details of ASN.1 formatted data to a string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string TextDumpToString(
string fileOrPEMString,
.Options options = Asn1.Options.Default
Asn1)
Filename of ASN.1 formatted data file to be analyzed (or a string containing its base64 or PEM representation)
Option flags: set as zero for defaults.
String
String containing the output.
This function creates a temporary file in the system
TEMP
directory. This file is locked and is automatically
deleted after use.
// Very simple ASN.1 data encoded in base64
string s = Asn1.TextDumpToString("MAQwAgUA");
.Assert(s.Length > 0, "Asn1.TextDumpToString failed");
Debug.WriteLine(s);
Console/*
30 04 --SEQUENCE/4 bytes
30 02 --SEQUENCE/2 bytes
05 00 --NULL/0 bytes
--(6 bytes) */
// An X.509 certificate file
= Asn1.TextDumpToString("smallca.cer");
s .WriteLine(s);
Console/*
30 81 e0 --SEQUENCE/224 bytes
30 81 9a --SEQUENCE/154 bytes
02 01 --INTEGER/1 bytes
01
30 0d --SEQUENCE/13 bytes
06 09 --OBJECTIDENTIFIER/9 bytes
2a 86 48 86 f7 0d 01 01 05
--sha1WithRSAEncryption (1.2.840.113549.1.1.5)
05 00 --NULL/0 bytes
30 0c --SEQUENCE/12 bytes
31 0a --SET/10 bytes
30 08 --SEQUENCE/8 bytes
06 03 --OBJECTIDENTIFIER/3 bytes
55 04 03
--commonName (2.5.4.3)
13 01 --PRINTABLESTRING/1 bytes
41
--'A'
[===cut===]
30 0d --SEQUENCE/13 bytes
06 09 --OBJECTIDENTIFIER/9 bytes
2a 86 48 86 f7 0d 01 01 05
--sha1WithRSAEncryption (1.2.840.113549.1.1.5)
05 00 --NULL/0 bytes
03 32 --BITSTRING/50 bytes
00 --0 unused bits
01 9a 9b b2 ec b9 cd fd 66 c6 94 5b 2e d6 96 dc
32 87 68 da 5e 6f 2e 5d 5a 7f e6 09 2e 60 8f 8c
45 a5 18 7e 06 1c e9 81 aa ea d6 f2 e3 14 7d 25
91
--(227 bytes) */
Asn1 Class
CryptoSysPKI Namespace
Describe the type of ASN.1 data.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string Type(
string fileOrPEMString
)
Filename of ASN.1 formatted data file to be analyzed (or a string containing its base64 or PEM representation)
String
String containing the name of the type of ASN.1 data or the empty string
if not found
The output is a string describing the most likely type of the ASN.1-formatted data, or an empty string (““) if the type cannot be determined. The following types are detected: | Output string value | ASN.1 object type | Reference | | ————————— | ———————– | —————— | | EC PRIVATE KEY | ECPrivateKey | [RFC5915] | | EC PRIVATE KEY | ECPrivateKey | [RFC5915] | | OCSP REQUEST | OCSPRequest | [RFC6960] | | OCSP RESPONSE | OCSPResponse | [RFC6960] | | PKCS1 RSA PRIVATE KEY | RSAPrivateKey | [RFC3447] | | PKCS1 RSA PUBLIC KEY | RSAPublicKey | [RFC3447] | | PKCS10 CERTIFICATE REQUEST | CertificationRequest | [RFC2986] | | PKCS12 PFX | PFX | [RFC7292] | | PKCS7 CERTIFICATE CHAIN | ContentInfo | [RFC5652] | | PKCS7/CMS COMPRESSED DATA | ContentInfo | [RFC3274] | | PKCS7/CMS DATA | ContentInfo | [RFC5652] | | PKCS7/CMS ENVELOPED DATA | ContentInfo | [RFC5652] | | CMS AUTH ENVELOPED DATA | ContentInfo | [RFC5083] | | PKCS7/CMS SIGNED DATA | ContentInfo | [RFC5652] | | PKCS8 ENCRYPTED PRIVATE KEY | EncryptedPrivateKeyInfo | [RFC5208][RFC5958] | | PKCS8 PRIVATE KEY INFO | PrivateKeyInfo | [RFC5208][RFC5958] | | PKCS8 ONE ASYMMETRIC KEY | OneAsymmetricKey | [RFC5958] | | PUBLIC KEY INFO | SubjectPublicKeyInfo | [RFC3279][RFC5480] | | X509 CERTIFICATE | Certificate | [RFC5280] | | X509 CRL | CertificateList | [RFC5280] | Note that these descriptions are not necessarily those used as labels for PEM formatted files defined in [RFC7468].
.WriteLine("Print type names of various ASN.1 data files...");
Consolestring fname, s;
= "smallca.cer";
fname = Asn1.Type(fname);
s .WriteLine("Asn1.Type('" + fname + "')=" + s);
Console// Asn1.Type('smallca.cer')=X509 CERTIFICATE
= "AlicePrivRSASign.p8e";
fname = Asn1.Type(fname);
s .WriteLine("Asn1.Type('" + fname + "')=" + s);
Console// Asn1.Type('AlicePrivRSASign.p8e')=PKCS8 ENCRYPTED PRIVATE KEY
Asn1 Class
CryptoSysPKI Namespace
Generic Block Cipher
System.Object
CryptoSysPKI.Cipher
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Cipher
The Cipher type exposes the following members.
Name | Description |
---|---|
BlockBytes | Return the block size in bytes for a given cipher algorithm. |
Decrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode) | Decrypt data block in byte array. |
Decrypt(String, String, String, CipherAlgorithm, Mode) | Decrypt data block as hex-encoded string. |
Decrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode, Padding, Cipher.Opts) | Decrypt data in a byte array using the specified block cipher algorithm, mode and padding. |
Decrypt(String, String, String, CipherAlgorithm, Mode, Padding, Cipher.Opts) | Decrypt hex-encoded data using specified block cipher algorithm, mode and padding. |
DecryptAEAD(Byte[], Byte[], Byte[], AeadAlgorithm) | Decrypt data using the AES-GCM authenticated encryption algorithm. |
DecryptAEAD(Byte[], Byte[], Byte[], Byte[], AeadAlgorithm, Cipher.Opts) | Decrypt data using the AES-GCM authenticated encryption algorithm with AAD and options. |
Encrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode) | Encrypt data block in byte array. |
Encrypt(String, String, String, CipherAlgorithm, Mode) | Encrypt data block as hex-encoded string. |
Encrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode, Padding, Cipher.Opts) | Encrypt data in a byte array using the specified block cipher algorithm, mode and padding. |
Encrypt(String, String, String, CipherAlgorithm, Mode, Padding, Cipher.Opts) | Encrypt hex-encoded data using specified block cipher algorithm, mode and padding. |
EncryptAEAD(Byte[], Byte[], Byte[], AeadAlgorithm) | Encrypt data using the AES-GCM authenticated encryption algorithm. |
EncryptAEAD(Byte[], Byte[], Byte[], Byte[], AeadAlgorithm, Cipher.Opts) | Encrypt data using the AES-GCM authenticated encryption algorithm with AAD and options. |
FileDecrypt(String, String, Byte[], Byte[], CipherAlgorithm, Mode, Padding, Cipher.Opts) | Decrypt a file. |
FileDecrypt(String, String, String, String, CipherAlgorithm, Mode, Padding, Cipher.Opts) | Decrypt a file passing key and IV as hex strings. |
FileEncrypt(String, String, Byte[], Byte[], CipherAlgorithm, Mode, Padding, Cipher.Opts) | Encrypt a file. |
FileEncrypt(String, String, String, String, CipherAlgorithm, Mode, Padding, Cipher.Opts) | Encrypt a file passing key and IV as hex strings. |
KeyBytes | Return the key size in bytes for a given cipher algorithm. |
KeyUnwrap | Unwrap (decrypt) key material with a key-encryption key. |
KeyWrap | Wrap (encrypt) key material with a key-encryption key. |
Pad(Byte[], CipherAlgorithm, Padding) | Pad byte array to correct length for ECB and CBC encryption. |
Pad(String, CipherAlgorithm, Padding) | Pad hex-encoded string to correct length for ECB and CBC encryption. |
Unpad(Byte[], CipherAlgorithm, Padding) | Remove padding from an encryption block. |
Unpad(String, CipherAlgorithm, Padding) | Remove padding from a hex-encoded encryption block. |
Return the block size in bytes for a given cipher algorithm.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int BlockBytes(
CipherAlgorithm alg)
Cipher algorithm
Int32
Block size in bytes
Cipher Class
CryptoSysPKI Namespace
Decrypt data block in byte array.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Decrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode) | Decrypt data block in byte array. |
Decrypt(String, String, String, CipherAlgorithm, Mode) | Decrypt data block as hex-encoded string. |
Decrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode, Padding, Cipher.Opts) | Decrypt data in a byte array using the specified block cipher algorithm, mode and padding. |
Decrypt(String, String, String, CipherAlgorithm, Mode, Padding, Cipher.Opts) | Decrypt hex-encoded data using specified block cipher algorithm, mode and padding. |
public static byte[] Decrypt(
byte[] input,
byte[] key,
byte[] iv,
,
CipherAlgorithm cipherAlg
Mode mode)
Input data to be decrypted
Key of exact length for block cipher algorithm
Initialization Vector (IV) of exactly the block size or
null
for ECB mode
Cipher algorithm
Cipher mode
Byte[]
Decrypted data in byte array or empty array on error
For ECB and CBC modes, input data length must be an exact multiple of the block length.
Cipher Class
CryptoSysPKI Namespace
Decrypt data block as hex-encoded string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Decrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode) | Decrypt data block in byte array. |
Decrypt(String, String, String, CipherAlgorithm, Mode) | Decrypt data block as hex-encoded string. |
Decrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode, Padding, Cipher.Opts) | Decrypt data in a byte array using the specified block cipher algorithm, mode and padding. |
Decrypt(String, String, String, CipherAlgorithm, Mode, Padding, Cipher.Opts) | Decrypt hex-encoded data using specified block cipher algorithm, mode and padding. |
public static string Decrypt(
string inputHex,
string keyHex,
string ivHex,
,
CipherAlgorithm cipherAlg
Mode mode)
Hex-encoded input data
Hex-encoded key representing exact key length
Hex-encoded IV representing exact block length or ""
for
ECB mode
Cipher Algorithm
Cipher Mode
String
Decrypted plaintext in hex-encoded string or empty string on error
For ECB and CBC modes, input data length must represent an exact multiple of the block length.
Cipher Class
CryptoSysPKI Namespace
Decrypt data in a byte array using the specified block cipher algorithm, mode and padding.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Decrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode) | Decrypt data block in byte array. |
Decrypt(String, String, String, CipherAlgorithm, Mode) | Decrypt data block as hex-encoded string. |
Decrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode, Padding, Cipher.Opts) | Decrypt data in a byte array using the specified block cipher algorithm, mode and padding. |
Decrypt(String, String, String, CipherAlgorithm, Mode, Padding, Cipher.Opts) | Decrypt hex-encoded data using specified block cipher algorithm, mode and padding. |
public static byte[] Decrypt(
byte[] input,
byte[] key,
byte[] iv,
,
CipherAlgorithm cipherAlg,
Mode mode= Padding.Default,
Padding pad .Opts opts = Cipher.Opts.Default
Cipher)
Input data to be decrypted
Key of exact length for block cipher algorithm
Initialization Vector (IV) of exactly the block size, or
null
for ECB mode or if IV is prefixed.
Cipher algorithm
Cipher mode
Padding method to use
Advanced options. Use Cipher.Opts.PrefixIV to expect the IV to be prepended to the input.
Byte[]
Decrypted plaintext in byte array or empty array on error
Default padding is Pkcs5
for ECB and CBC mode and
NoPad
for all other modes. It is an error if the specified
padding is not found after decryption.
Cipher Class
CryptoSysPKI Namespace
Decrypt hex-encoded data using specified block cipher algorithm, mode and padding.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Decrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode) | Decrypt data block in byte array. |
Decrypt(String, String, String, CipherAlgorithm, Mode) | Decrypt data block as hex-encoded string. |
Decrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode, Padding, Cipher.Opts) | Decrypt data in a byte array using the specified block cipher algorithm, mode and padding. |
Decrypt(String, String, String, CipherAlgorithm, Mode, Padding, Cipher.Opts) | Decrypt hex-encoded data using specified block cipher algorithm, mode and padding. |
public static string Decrypt(
string inputHex,
string keyHex,
string ivHex,
,
CipherAlgorithm cipherAlg,
Mode mode= Padding.Default,
Padding pad .Opts opts = Cipher.Opts.Default
Cipher)
Hex-encoded input data
Hex-encoded key representing exact key length
Hex-encoded IV representing exact block length, or ""
for ECB mode or if IV is prefixed.
Cipher Algorithm
Cipher Mode
Padding method to use
Advanced options. Use Cipher.Opts.PrefixIV to expect the IV to be prepended to the input.
String
Decrypted plaintex in hex-encoded string or empty string on error
Input data may be any even number of hex characters, but not zero.
Default padding is Pkcs5
for ECB and CBC mode and
NoPad
for all other modes.
Cipher Class
CryptoSysPKI Namespace
Decrypt data using the AES-GCM authenticated encryption algorithm.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
DecryptAEAD(Byte[], Byte[], Byte[], AeadAlgorithm) | Decrypt data using the AES-GCM authenticated encryption algorithm. |
DecryptAEAD(Byte[], Byte[], Byte[], Byte[], AeadAlgorithm, Cipher.Opts) | Decrypt data using the AES-GCM authenticated encryption algorithm with AAD and options. |
public static byte[] DecryptAEAD(
byte[] input,
byte[] key,
byte[] iv,
AeadAlgorithm aeadAlg)
Input data to be decrypted.
Key of exact length for algorithm (16, 24 or 32 bytes).
Initialization Vector (IV) (aka nonce) exactly 12 bytes long.
Authenticated encryption algorithm.
Byte[]
Plaintext in a byte array, or empty array on error (an empty array may
also be the correct result - check General.ErrorCode for
details).
The input must include the 16-byte tag appended to the ciphertext. The output will be exactly 16 bytes shorter than the input. In all cases the IV must be exactly 12 bytes (96 bits) and the tag must be exactly 16 bytes (128 bits).
Cipher Class
CryptoSysPKI Namespace
Return the error code of the first error that occurred when calling the last function.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int ErrorCode()
Int32
Error code
General Class
CryptoSysPKI Namespace
Decrypt data using the AES-GCM authenticated encryption algorithm with AAD and options.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
DecryptAEAD(Byte[], Byte[], Byte[], AeadAlgorithm) | Decrypt data using the AES-GCM authenticated encryption algorithm. |
DecryptAEAD(Byte[], Byte[], Byte[], Byte[], AeadAlgorithm, Cipher.Opts) | Decrypt data using the AES-GCM authenticated encryption algorithm with AAD and options. |
public static byte[] DecryptAEAD(
byte[] input,
byte[] key,
byte[] iv,
byte[] aad,
,
AeadAlgorithm aeadAlg.Opts opts
Cipher)
Input data to be decrypted.
Key of exact length for algorithm (16, 24 or 32 bytes).
Initialization Vector (IV) (aka nonce) exactly 12 bytes long, if not provided in input.
Additional authenticated data (optional) - set as null
to ignore.
Authenticated encryption algorithm.
Advanced options. Use Cipher.Opts.PrefixIV to expect the IV to be prepended at the start of the input.
Byte[]
Plaintext in a byte array, or empty array on error (an empty array may
also be the correct result - check General.ErrorCode for
details).
The input must include the 16-byte tag appended to the ciphertext and
may include a 12-byte prefixed IV. The output will either be exactly 16
bytes shorter than the input, or exactly 28 bytes shorter if the
Cipher.Opts.PrefixIV
option is used. In all cases the IV
must be exactly 12 bytes (96 bits) and the tag must be exactly 16 bytes
(128 bits). If additional authentication data (AAD) was provided during
encryption then the exact same AAD data must be provided here.
Cipher Class
CryptoSysPKI Namespace
Encrypt data block in byte array.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Encrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode) | Encrypt data block in byte array. |
Encrypt(String, String, String, CipherAlgorithm, Mode) | Encrypt data block as hex-encoded string. |
Encrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode, Padding, Cipher.Opts) | Encrypt data in a byte array using the specified block cipher algorithm, mode and padding. |
Encrypt(String, String, String, CipherAlgorithm, Mode, Padding, Cipher.Opts) | Encrypt hex-encoded data using specified block cipher algorithm, mode and padding. |
public static byte[] Encrypt(
byte[] input,
byte[] key,
byte[] iv,
,
CipherAlgorithm cipherAlg
Mode mode)
Input data to be encrypted
Key of exact length for block cipher algorithm
Initialization Vector (IV) of exactly the block size or
null
for ECB mode
Cipher algorithm
Cipher mode
Byte[]
Ciphertext in byte array or empty array on error
For ECB and CBC modes, input data length must be an exact multiple of the block length.
Cipher Class
CryptoSysPKI Namespace
Encrypt data block as hex-encoded string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Encrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode) | Encrypt data block in byte array. |
Encrypt(String, String, String, CipherAlgorithm, Mode) | Encrypt data block as hex-encoded string. |
Encrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode, Padding, Cipher.Opts) | Encrypt data in a byte array using the specified block cipher algorithm, mode and padding. |
Encrypt(String, String, String, CipherAlgorithm, Mode, Padding, Cipher.Opts) | Encrypt hex-encoded data using specified block cipher algorithm, mode and padding. |
public static string Encrypt(
string inputHex,
string keyHex,
string ivHex,
,
CipherAlgorithm cipherAlg
Mode mode)
Hex-encoded input data
Hex-encoded key representing exact key length
Hex-encoded IV representing exact block length or ""
for
ECB mode
Cipher algorithm
Cipher mode
String
Ciphertext in hex-encoded string or empty string on error
For ECB and CBC modes, input data length must be an exact multiple of the block length.
Cipher Class
CryptoSysPKI Namespace
Encrypt data in a byte array using the specified block cipher algorithm, mode and padding.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Encrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode) | Encrypt data block in byte array. |
Encrypt(String, String, String, CipherAlgorithm, Mode) | Encrypt data block as hex-encoded string. |
Encrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode, Padding, Cipher.Opts) | Encrypt data in a byte array using the specified block cipher algorithm, mode and padding. |
Encrypt(String, String, String, CipherAlgorithm, Mode, Padding, Cipher.Opts) | Encrypt hex-encoded data using specified block cipher algorithm, mode and padding. |
public static byte[] Encrypt(
byte[] input,
byte[] key,
byte[] iv,
,
CipherAlgorithm cipherAlg,
Mode mode= Padding.Default,
Padding pad .Opts opts = Cipher.Opts.Default
Cipher)
Input data to be encrypted
Key of exact length for block cipher algorithm
Initialization Vector (IV) of exactly the block size or
null
for ECB mode.
Cipher algorithm
Cipher mode
Padding method to use
Advanced options. Use Cipher.Opts.PrefixIV to prepend the IV to the output.
Byte[]
Ciphertext in byte array or empty array on error
Default padding is Pkcs5
for ECB and CBC mode and
NoPad
for all other modes.
Cipher Class
CryptoSysPKI Namespace
Encrypt hex-encoded data using specified block cipher algorithm, mode and padding.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Encrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode) | Encrypt data block in byte array. |
Encrypt(String, String, String, CipherAlgorithm, Mode) | Encrypt data block as hex-encoded string. |
Encrypt(Byte[], Byte[], Byte[], CipherAlgorithm, Mode, Padding, Cipher.Opts) | Encrypt data in a byte array using the specified block cipher algorithm, mode and padding. |
Encrypt(String, String, String, CipherAlgorithm, Mode, Padding, Cipher.Opts) | Encrypt hex-encoded data using specified block cipher algorithm, mode and padding. |
public static string Encrypt(
string inputHex,
string keyHex,
string ivHex,
,
CipherAlgorithm cipherAlg,
Mode mode= Padding.Default,
Padding pad .Opts opts = Cipher.Opts.Default
Cipher)
Hex-encoded input data
Hex-encoded key representing exact key length
Hex-encoded IV representing exact block length or ""
for
ECB mode
Cipher Algorithm
Cipher Mode
Padding method to use (optional)
Advanced options. Use Cipher.Opts.PrefixIV to prepend the IV to the output.
String
Encrypted ciphertext in hex-encoded string or empty string on error
Input data may be any even number of hex characters, but not zero.
Default padding is Pkcs5
for ECB and CBC mode and
NoPad
for all other modes.
Cipher Class
CryptoSysPKI Namespace
Encrypt data using the AES-GCM authenticated encryption algorithm.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
EncryptAEAD(Byte[], Byte[], Byte[], AeadAlgorithm) | Encrypt data using the AES-GCM authenticated encryption algorithm. |
EncryptAEAD(Byte[], Byte[], Byte[], Byte[], AeadAlgorithm, Cipher.Opts) | Encrypt data using the AES-GCM authenticated encryption algorithm with AAD and options. |
public static byte[] EncryptAEAD(
byte[] input,
byte[] key,
byte[] iv,
AeadAlgorithm aeadAlg)
Input data to be encrypted.
Key of exact length for algorithm (16, 24 or 32 bytes).
Initialization Vector (IV) (aka nonce) exactly 12 bytes long.
Authenticated encryption algorithm.
Byte[]
Ciphertext with tag appended in a byte array, or empty array on
error.
The output will be exactly 16 bytes longer than the input.
Cipher Class
CryptoSysPKI Namespace
Encrypt data using the AES-GCM authenticated encryption algorithm with AAD and options.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
EncryptAEAD(Byte[], Byte[], Byte[], AeadAlgorithm) | Encrypt data using the AES-GCM authenticated encryption algorithm. |
EncryptAEAD(Byte[], Byte[], Byte[], Byte[], AeadAlgorithm, Cipher.Opts) | Encrypt data using the AES-GCM authenticated encryption algorithm with AAD and options. |
public static byte[] EncryptAEAD(
byte[] input,
byte[] key,
byte[] iv,
byte[] aad,
,
AeadAlgorithm aeadAlg.Opts opts
Cipher)
Input data to be encrypted.
Key of exact length for algorithm (16, 24 or 32 bytes).
Initialization Vector (IV) (aka nonce) exactly 12 bytes long.
Additional authenticated data (optional) - set as null
to ignore.
Authenticated encryption algorithm.
Advanced options. Use Cipher.Opts.PrefixIV to prepend the 12-byte IV to the output
Byte[]
Ciphertext with tag appended in a byte array, or empty array on
error.
The output will either be exactly 16 bytes longer than the input, or
exactly 28 bytes longer if Cipher.Opts.PrefixIV
is
used.
Cipher Class
CryptoSysPKI Namespace
Decrypt a file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
FileDecrypt(String, String, Byte[], Byte[], CipherAlgorithm, Mode, Padding, Cipher.Opts) | Decrypt a file. |
FileDecrypt(String, String, String, String, CipherAlgorithm, Mode, Padding, Cipher.Opts) | Decrypt a file passing key and IV as hex strings. |
public static int FileDecrypt(
string fileOut,
string fileIn,
byte[] key,
byte[] iv,
,
CipherAlgorithm cipherAlg,
Mode mode= Padding.Default,
Padding pad .Opts opts = Cipher.Opts.Default
Cipher)
Name of output file to be created or overwritten
Name of input file
Key of of exact length for block cipher algorithm
Initialization Vector (IV) of exactly the block size, or
null
for ECB mode or if IV is prefixed.
Cipher Algorithm
Cipher Mode
Padding method to use (optional, ECB and CBC modes only,
default=Pkcs5
)
Advanced options. Use Cipher.Opts.PrefixIV to expect the IV to be prepended to the input.
Int32
0 if successful or non-zero error
code
fileOut
and fileIn
must
not be the same
Cipher Class
CryptoSysPKI Namespace
Decrypt a file passing key and IV as hex strings.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
FileDecrypt(String, String, Byte[], Byte[], CipherAlgorithm, Mode, Padding, Cipher.Opts) | Decrypt a file. |
FileDecrypt(String, String, String, String, CipherAlgorithm, Mode, Padding, Cipher.Opts) | Decrypt a file passing key and IV as hex strings. |
public static int FileDecrypt(
string fileOut,
string fileIn,
string keyHex,
string ivHex,
,
CipherAlgorithm cipherAlg,
Mode mode= Padding.Default,
Padding pad .Opts opts = Cipher.Opts.Default
Cipher)
Name of output file to be created or overwritten
Name of input file, in binary format.
Hex-encoded key of exact length
Hex-encoded IV, or ""
for ECB mode or if IV is
prefixed.
Cipher Algorithm
Cipher Mode
Padding method to use (optional, ECB and CBC modes only,
default=Pkcs5
)
Advanced options. Use Cipher.Opts.PrefixIV to expect the IV to be prepended to the input.
Int32
0 if successful or non-zero error
code
fileOut
and fileIn
must
not be the same. The output file is in binary
format.
Cipher Class
CryptoSysPKI Namespace
Encrypt a file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
FileEncrypt(String, String, Byte[], Byte[], CipherAlgorithm, Mode, Padding, Cipher.Opts) | Encrypt a file. |
FileEncrypt(String, String, String, String, CipherAlgorithm, Mode, Padding, Cipher.Opts) | Encrypt a file passing key and IV as hex strings. |
public static int FileEncrypt(
string fileOut,
string fileIn,
byte[] key,
byte[] iv,
,
CipherAlgorithm cipherAlg,
Mode mode= Padding.Default,
Padding pad .Opts opts = Cipher.Opts.Default
Cipher)
Name of output file to be created or overwritten
Name of input file
Key of of exact length for block cipher algorithm
Initialization Vector (IV) of exactly the block size or
null
for ECB mode
Cipher Algorithm
Cipher Mode
Padding method to use (optional, ECB and CBC modes only,
default=Pkcs5
)
Advanced options. Use Cipher.Opts.PrefixIV to prepend the IV to the output.
Int32
0 if successful or non-zero error
code
fileOut
and fileIn
must
not be the same
Cipher Class
CryptoSysPKI Namespace
Encrypt a file passing key and IV as hex strings.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
FileEncrypt(String, String, Byte[], Byte[], CipherAlgorithm, Mode, Padding, Cipher.Opts) | Encrypt a file. |
FileEncrypt(String, String, String, String, CipherAlgorithm, Mode, Padding, Cipher.Opts) | Encrypt a file passing key and IV as hex strings. |
public static int FileEncrypt(
string fileOut,
string fileIn,
string keyHex,
string ivHex,
,
CipherAlgorithm cipherAlg,
Mode mode= Padding.Default,
Padding pad .Opts opts = Cipher.Opts.Default
Cipher)
Name of output file to be created or overwritten
Name of input file, in binary format.
Hex-encoded key of exact length
Hex-encoded IV or ""
for ECB mode
Cipher Algorithm
Cipher Mode
Padding method to use (optional, ECB and CBC modes only,
default=Pkcs5
)
Advanced options. Use Cipher.Opts.PrefixIV to prepend the IV to the output.
Int32
0 if successful or non-zero error
code
fileOut
and fileIn
must
not be the same. The output file is in binary
format.
Cipher Class
CryptoSysPKI Namespace
Return the key size in bytes for a given cipher algorithm.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int KeyBytes(
CipherAlgorithm alg)
Cipher algorithm
Int32
Key size in bytes
Cipher Class
CryptoSysPKI Namespace
Unwrap (decrypt) key material with a key-encryption key.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] KeyUnwrap(
byte[] data,
byte[] kek,
CipherAlgorithm cipherAlg)
Wrapped key
Key encryption key
Block cipher to use for wrapping
Byte[]
Unwrapped key material (or empty array on error)
Cipher Class
CryptoSysPKI Namespace
Wrap (encrypt) key material with a key-encryption key.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] KeyWrap(
byte[] data,
byte[] kek,
CipherAlgorithm cipherAlg)
Key material to be wrapped
Key encryption key
Block cipher to use for wrapping
Byte[]
Wrapped key (or empty array on error)
Cipher Class
CryptoSysPKI Namespace
Pad byte array to correct length for ECB and CBC encryption.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Pad(Byte[], CipherAlgorithm, Padding) | Pad byte array to correct length for ECB and CBC encryption. |
Pad(String, CipherAlgorithm, Padding) | Pad hex-encoded string to correct length for ECB and CBC encryption. |
public static byte[] Pad(
byte[] input,
,
CipherAlgorithm cipherAlg= Padding.Pkcs5
Padding pad )
Data to be padded
Block cipher being used
Padding method to use (default is PKCS#5/#7)
Byte[]
Padded data in byte array
Cipher Class
CryptoSysPKI Namespace
Pad hex-encoded string to correct length for ECB and CBC encryption.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Pad(Byte[], CipherAlgorithm, Padding) | Pad byte array to correct length for ECB and CBC encryption. |
Pad(String, CipherAlgorithm, Padding) | Pad hex-encoded string to correct length for ECB and CBC encryption. |
public static string Pad(
string inputHex,
,
CipherAlgorithm cipherAlg= Padding.Pkcs5
Padding pad )
Hex-encoded data to be padded
Block cipher being used
Padding method to use (default is PKCS#5/#7)
String
Padded data in hex-encoded string
Cipher Class
CryptoSysPKI Namespace
Remove padding from an encryption block.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Unpad(Byte[], CipherAlgorithm, Padding) | Remove padding from an encryption block. |
Unpad(String, CipherAlgorithm, Padding) | Remove padding from a hex-encoded encryption block. |
public static byte[] Unpad(
byte[] input,
,
CipherAlgorithm cipherAlg= Padding.Pkcs5
Padding pad )
Padded data
Block cipher being used
Padding method to use (default is PKCS#5/#7)
Byte[]
Unpadded data in byte array.
Unless pad
is NoPad
, the unpadded output is
always shorter than the padded input. An error is indicated by returning
the original data. If the output length equals the input length, then
error.
Cipher Class
CryptoSysPKI Namespace
Remove padding from a hex-encoded encryption block.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Unpad(Byte[], CipherAlgorithm, Padding) | Remove padding from an encryption block. |
Unpad(String, CipherAlgorithm, Padding) | Remove padding from a hex-encoded encryption block. |
public static string Unpad(
string inputHex,
,
CipherAlgorithm cipherAlg= Padding.Pkcs5
Padding pad )
Hex-encoded padded data
Block cipher being used
Padding method to use (default is PKCS#5/#7)
String
Unpadded data in hex-encoded string.
Unless pad
is NoPad
, the unpadded output is
always shorter than the padded input. An error is indicated by returning
the original data. If the output length equals the input length, then
error.
Cipher Class
CryptoSysPKI Namespace
Create, read and analyze Cryptographic Message Syntax (CMS) objects.
System.Object
CryptoSysPKI.Cms
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Cms
The Cms type exposes the following members.
Name | Description |
---|---|
GetSigDataDigest | Extract the message digest from a signed-data CMS object file and verify the signature. |
GetSigHashAlgorithm | Find ID of message digest hash algorithm used to make signature. |
MakeComprData | Create a new CMS compressed-data file (.p7z) from an existing input file. |
MakeDetachedSig | Create a “detached signature” CMS signed-data object file from a message digest of the content (advanced algorithms). |
MakeEnvData(String, String, String, CipherAlgorithm, Cms.EnvDataOptions) | Create a CMS enveloped-data object (default recipient parameters). |
MakeEnvData(String, String, String, CipherAlgorithm, Cms.KeyEncrAlgorithm, HashAlgorithm, Cms.EnvDataOptions, Kdf.KdfAlg, Kdf.KeyWrapAlg, String, Int32, Cms.ContentEncrAlg) | Create a CMS enveloped-data object (advanced options). |
MakeEnvDataFromBytes | Create a CMS enveloped-data object from data in a byte array. |
MakeEnvDataFromString(String, String, String, CipherAlgorithm, Cms.EnvDataOptions) | Create a CMS enveloped-data object from an ASCII string (default recipient parameters). |
MakeEnvDataFromString(String, String, String, CipherAlgorithm, Cms.KeyEncrAlgorithm, HashAlgorithm, Cms.EnvDataOptions, Kdf.KdfAlg, Kdf.KeyWrapAlg, String, Int32, Cms.ContentEncrAlg) | Create a CMS enveloped-data object from an ASCII string (advanced options). |
MakeSigData(String, String, String, String, Cms.SigAlg, Cms.SigDataOptions) | Create a CMS object of type SignedData from an input data file (advanced options including RSA-PSS). |
MakeSigData(String, String, String, String, HashAlgorithm, Cms.SigDataOptions) | Create a CMS object of type SignedData from an input data file using RSASSA-PKCS1V1_5 with options. |
MakeSigDataFromBytes | Create a CMS object of type SignedData from an array of bytes. |
MakeSigDataFromPseudo | Create a SignedData object from a “pseudo” object. |
MakeSigDataFromSigValue | Create a CMS object of type SignedData using a pre-computed signature (advanced algorithms). |
MakeSigDataFromString(String, String, String, String, Cms.SigAlg, Cms.SigDataOptions) | Create a CMS object of type SignedData from an input string (advanced options including RSA-PSS). |
MakeSigDataFromString(String, String, String, String, HashAlgorithm, Cms.SigDataOptions) | Create a CMS object of type SignedData from an input string using RSASSA-PKCS1V1_5 with options. |
QueryEnvData | Query a CMS enveloped-data object file for selected information. |
QuerySigData | Query a CMS signed-data object for selected information. |
ReadComprData | Read and extract the decompressed contents of a CMS compressed-data file. |
ReadEnvDataToBytes | Read and decrypt a CMS enveloped-data object to a byte array. |
ReadEnvDataToFile | Read and decrypt a CMS enveloped-data object to a file. |
ReadEnvDataToString | Read and decrypt a CMS enveloped-data object to a string. |
ReadSigDataToBytes | Read the content from a CMS signed-data object directly into a byte array. |
ReadSigDataToFile | Read the content from a CMS signed-data object file. |
ReadSigDataToString | Read the content from a CMS signed-data object directly into a string. |
VerifySigData | Verify the signature and content of a signed-data CMS object file. |
Extract the message digest from a signed-data CMS object file and verify the signature.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string GetSigDataDigest(
string inputFile,
string certFile
)
name of file containing CMS signed-data object
an (optional) X.509 certificate file to be used to identify the signer
String
Hash value in hex format or an empty string if error
If no certificate is given, it will use the first valid SignerInfo and certificate pair it finds in the SignedData. RSASSA-PKCS1V1_5 only.
Cms Class
CryptoSysPKI Namespace
Find ID of message digest hash algorithm used to make signature.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int GetSigHashAlgorithm(
string inputFile,
string certFile
)
name of file containing CMS signed-data object
an (optional) X.509 certificate file to be used to identify the signer
Int32
0=SHA-1, 1=MD5, 2=MD2, 3=SHA-256, 4=SHA-384, 5=SHA-512, 6=SHA-224; or a
negative error code
This method returns an integer ID number. Alternatively, use
Cms.QuerySigData(inputFile, "digestAlgorithm")
to get the
name directly as a string, e.g. "sha1"
. See QuerySigData(String, String)
Cms Class
CryptoSysPKI Namespace
Create a new CMS compressed-data file (.p7z) from an existing input file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int MakeComprData(
string outputFile,
string inputFile
)
Output file to be created
Input data file
Int32
Zero if successful; otherwise it returns a non-zero error code
Cms Class
CryptoSysPKI Namespace
Create a “detached signature” CMS signed-data object file from a message digest of the content (advanced algorithms).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int MakeDetachedSig(
string outputFile,
string hexDigest,
string certList,
string privateKey,
= HashAlgorithm.Sha1,
HashAlgorithm hashAlg .SigDataOptions advOptions = Cms.SigDataOptions.Default
Cms)
name of output file to be created
string containing message digest in hex format
filename of the signer’s certificate and (optionally) a list of other certificates to be included in the output, separated by semi-colons (;) Alternatively specify a single PKCS#7 certificate chain file (.p7c/.p7b) containing the signer’s certificate.
Private key data for the sender.
Message digest algorithm to be used in signature [default=SHA-1]
Advanced option flags. See Cms.SigDataOptions.
Int32
Zero if successful; otherwise it returns an error code
RSASSA-PKCS1V1_5 only.
Cms Class
CryptoSysPKI Namespace
Create a CMS enveloped-data object (default recipient parameters).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
MakeEnvData(String, String, String, CipherAlgorithm, Cms.EnvDataOptions) | Create a CMS enveloped-data object (default recipient parameters). |
MakeEnvData(String, String, String, CipherAlgorithm, Cms.KeyEncrAlgorithm, HashAlgorithm, Cms.EnvDataOptions, Kdf.KdfAlg, Kdf.KeyWrapAlg, String, Int32, Cms.ContentEncrAlg) | Create a CMS enveloped-data object (advanced options). |
public static int MakeEnvData(
string outputFile,
string inputFile,
string certList,
,
CipherAlgorithm cipherAlg.EnvDataOptions advOptions
Cms)
Name of output file to be created.
Input data file.
List of recipient X.509 certificate filename(s), separated by semi-colons (;). Alternatively, specify a single PKCS#7 certificate chain file (.p7c/.p7b).
Content encryption algorithm [default=AES128-CBC].
Advanced options. See Cms.EnvDataOptions.
Int32
Number of successful recipients or a negative error code.
Cms Class
CryptoSysPKI Namespace
Create a CMS enveloped-data object (advanced options).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
MakeEnvData(String, String, String, CipherAlgorithm, Cms.EnvDataOptions) | Create a CMS enveloped-data object (default recipient parameters). |
MakeEnvData(String, String, String, CipherAlgorithm, Cms.KeyEncrAlgorithm, HashAlgorithm, Cms.EnvDataOptions, Kdf.KdfAlg, Kdf.KeyWrapAlg, String, Int32, Cms.ContentEncrAlg) | Create a CMS enveloped-data object (advanced options). |
public static int MakeEnvData(
string outputFile,
string inputFile,
string certList,
= ,
CipherAlgorithm cipherAlg .KeyEncrAlgorithm keyEncrAlg = Cms.KeyEncrAlgorithm.Default,
Cms= HashAlgorithm.Sha1,
HashAlgorithm hashAlg .EnvDataOptions advOptions = Cms.EnvDataOptions.None,
Cms.KdfAlg kdfAlg = Kdf.KdfAlg.X963,
Kdf.KeyWrapAlg keyWrapAlg = Kdf.KeyWrapAlg.Default,
Kdfstring keyString = "",
int count = 0,
.ContentEncrAlg contEncrAlg = Cms.ContentEncrAlg.Aes128
Cms)
Name of output file to be created.
Input data file.
List of one or more recipient X.509 certificate filenames, separated by semicolons (;). A certificate’s representation in base64 or as a PEM string may be used instead of a filename. Alternatively, specify a single PKCS#7 certificate chain file (.p7c/.p7b).
Special cases: Set as "type=@pwri"
to create a single
recipientInfo of the PasswordRecipientInfo
(pwri) type; or
set as "type=@kekri,keyid=<string>"
to create a
single recipientInfo of the KEKRecipientInfo
(kekri) type.
See Remarks.
Content encryption algorithm [default=ignored]. Deprecated: use
contEncrAlg
. (This parameter will be removed in a future
update)
Key encryption algorithm for ktri type [default=RSAES-PKCS-v1_5)]
Hash function where applicable. Must be one of the SHA-* family [default=SHA-1; SHA-256 for RSA-KEM]
Advanced options. See Cms.EnvDataOptions.
Key derivation function (KDF) for ECDH key agreement scheme (where applicable)
Key wrap algorithm for ECDH key agreement scheme or kekri type (default=match content encryption algorithm)
(formerly ukmString
) Use to pass optional additional
user key material (ukm) for KDF where KeyAgreement (kari) type is used.
Or use to pass the password for a pwri type or the key encryption key
(KEK) for a kekri type. Either pass a plain ASCII string,
e.g. "abc"
or use the format
"#x<hex-digits>"
to pass a string of arbitrary octet
values, e.g. "#xdeadbeef01"
to pass the 5 bytes
0xde,0xad,0xbe,0xef,0x01
. Required for pwri and kekri
types.
Optional iteration count for KDF in pwri type (default=4096) or tag length for AuthEnvelopedData (in range 12-16, default=16). Otherwise ignored.
Preferred way to specify content encryption algorithm with more
options. Takes precedence over cipherAlg
.
[default=AES128-CBC]
Int32
Number of successful recipients or a negative error code.
The output is a file containing a CMS EnvelopedData object or
AuthEnvelopedData object. New in [v22.0] use the preferred
contEncrAlg
parameter to specify the content-encryption
algorithm rather than cipherAlg
. If a list of certificates
is passed in certList
, the recipientInfo type is set
automatically depending on the public key found in each certificate, one
for each certificate. If the public key is RSA
(rsaEncryption
) then the key transport technique (ktri)
will be used for that particular recipientInfo. If the public key is a
supported ECC key, then the standard ECDH ephemeral-static key agreement
technique (kari) will be used as per [RFC5753] and [RFC8418].
Alternatively, use key encryption option Cms.KeyEncrAlgorithm.Rsa_Kem with an RSA public key, and the RSA-KEM algorithm using KEMRecipientInfo will be used for key encryption.
If certList
is set to "type=@pwri"
then a
single recipientInfo will be created of PasswordRecipientInfo type
(pwri). The password must be passed in the keyString
parameter. The parameters keyEncrAlg, kdfAlg and keyWrapAlg are ignored
in this case. If certList
is set to
"type=@kekri,keyid=<string>"
then a single
recipientInfo will be created of KEKRecipientInfo type (kekri). The key
encryption key (KEK) must be passed in the keyString
parameter. The parameters keyEncrAlg, hashAlg and kdfAlg are ignored in
this case.
// Create an enveloped CMS object (ktri type) to Bob using Bob's RSA key
= Cms.MakeEnvData("cms2bob_aes128.p7m", "excontent.txt", "BobRSASignByCarl.cer", CipherAlgorithm.Aes128, Cms.KeyEncrAlgorithm.Rsa_Oaep);
n
// Create an enveloped CMS object (kekri type) using a previously distributed symmetric key-encryption key (KEK)
= Cms.MakeEnvData("cms_envdata_kekri.p7m", "excontent.txt", "type=@kekri,keyid=ourcommonkey", CipherAlgorithm.Aes256,
n : HashAlgorithm.Sha256, keyWrapAlg:Kdf.KeyWrapAlg.Aes128_wrap, keyString: "#x0123456789ABCDEFF0E1D2C3B4A59687"); hashAlg
Cms Class
CryptoSysPKI Namespace
Create a CMS enveloped-data object from data in a byte array.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int MakeEnvDataFromBytes(
string outputFile,
byte[] inputData,
string certList,
= ,
CipherAlgorithm cipherAlg .KeyEncrAlgorithm keyEncrAlg = Cms.KeyEncrAlgorithm.Default,
Cms= HashAlgorithm.Sha1,
HashAlgorithm hashAlg .EnvDataOptions advOptions = Cms.EnvDataOptions.None,
Cms.KdfAlg kdfAlg = Kdf.KdfAlg.X963,
Kdf.KeyWrapAlg keyWrapAlg = Kdf.KeyWrapAlg.Default,
Kdfstring keyString = "",
int count = 0,
.ContentEncrAlg contEncrAlg = Cms.ContentEncrAlg.Aes128
Cms)
Output file to be created
Input data.
List of one or more recipient X.509 certificate filenames, separated by semicolons (;). A certificate’s representation in base64 or as a PEM string may be used instead of a filename. Alternatively, specify a single PKCS#7 certificate chain file (.p7c/.p7b).
Special cases: Set as "type=@pwri"
to create a single
recipientInfo of the PasswordRecipientInfo
(pwri) type; or
set as "type=@kekri,keyid=<string>"
to create a
single recipientInfo of the KEKRecipientInfo
(kekri) type.
See Remarks.
Content encryption algorithm [default=ignored]. Deprecated: use
contEncrAlg
. (This parameter will be removed in a future
update)
Key encryption algorithm for ktri type [default=RSAES-PKCS-v1_5)]
Hash function where applicable. Must be one of the SHA-* family [default=SHA-1; SHA-256 for RSA-KEM]
Advanced options. See Cms.EnvDataOptions.
Key derivation function (KDF) (where applicable)
Key wrap algorithm for ECDH key agreement scheme or kekri type (default=match content encryption algorithm)
(formerly ukmString
) Use to pass optional additional
user key material (ukm) for KDF where KeyAgreement (kari) type or
RSA-KEM is used. Or use to pass the password for a pwri type or the key
encryption key (KEK) for a kekri type. Either pass a plain ASCII string,
e.g. "abc"
or use the format
"#x<hex-digits>"
to pass a string of arbitrary octet
values, e.g. "#xdeadbeef01"
to pass the 5 bytes
0xde,0xad,0xbe,0xef,0x01
. Required for pwri and kekri
types.
Optional iteration count for KDF in pwri type (default=4096) or tag length for AuthEnvelopedData (in range 12-16, default=16). Otherwise ignored.
Alternative way to specify content encryption algorithm with more
options. Takes precedence over cipherAlg
.
[default=AES128-CBC]
Int32
Number of successful recipients or negative error code
Cms Class
CryptoSysPKI Namespace
Create a CMS enveloped-data object from an ASCII string (default recipient parameters).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
MakeEnvDataFromString(String, String, String, CipherAlgorithm, Cms.EnvDataOptions) | Create a CMS enveloped-data object from an ASCII string (default recipient parameters). |
MakeEnvDataFromString(String, String, String, CipherAlgorithm, Cms.KeyEncrAlgorithm, HashAlgorithm, Cms.EnvDataOptions, Kdf.KdfAlg, Kdf.KeyWrapAlg, String, Int32, Cms.ContentEncrAlg) | Create a CMS enveloped-data object from an ASCII string (advanced options). |
public static int MakeEnvDataFromString(
string outputFile,
string inputData,
string certList,
,
CipherAlgorithm cipherAlg.EnvDataOptions advOptions
Cms)
Output file to be created
Input data string, expected plain ASCII text.
List of recipient X.509 certificate filename(s), separated by semi-colons (;). Alternatively, specify a single PKCS#7 certificate chain file (.p7c/.p7b).
Content encryption algorithm [default=Triple DES]
Advanced options. See Cms.EnvDataOptions.
Int32
Number of successful recipients or negative error code
Cms Class
CryptoSysPKI Namespace
Create a CMS enveloped-data object from an ASCII string (advanced options).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
MakeEnvDataFromString(String, String, String, CipherAlgorithm, Cms.EnvDataOptions) | Create a CMS enveloped-data object from an ASCII string (default recipient parameters). |
MakeEnvDataFromString(String, String, String, CipherAlgorithm, Cms.KeyEncrAlgorithm, HashAlgorithm, Cms.EnvDataOptions, Kdf.KdfAlg, Kdf.KeyWrapAlg, String, Int32, Cms.ContentEncrAlg) | Create a CMS enveloped-data object from an ASCII string (advanced options). |
public static int MakeEnvDataFromString(
string outputFile,
string inputData,
string certList,
= ,
CipherAlgorithm cipherAlg .KeyEncrAlgorithm keyEncrAlg = Cms.KeyEncrAlgorithm.Default,
Cms= HashAlgorithm.Sha1,
HashAlgorithm hashAlg .EnvDataOptions advOptions = Cms.EnvDataOptions.None,
Cms.KdfAlg kdfAlg = Kdf.KdfAlg.X963,
Kdf.KeyWrapAlg keyWrapAlg = Kdf.KeyWrapAlg.Default,
Kdfstring keyString = "",
int count = 0,
.ContentEncrAlg contEncrAlg = Cms.ContentEncrAlg.Aes128
Cms)
Output file to be created
Input data string, expected plain ASCII text.
List of recipient X.509 certificate filename(s), separated by semi-colons (;). Alternatively, specify a single PKCS#7 certificate chain file (.p7c/.p7b).
Special cases: Set as "type=@pwri"
to create a single
recipientInfo of the PasswordRecipientInfo
type (pwri); or
set as "type=@kekri,keyid=<string>"
to create a
single recipientInfo of the KEKRecipientInfo
type (kekri).
See Remarks.
Content encryption algorithm [default=ignored]. Deprecated: use
contEncrAlg
. (This parameter will be removed in a future
update)
Key encryption algorithm [default=rsaEncryption
)]
Hash function where applicable. Must be one of the SHA-* family [default=SHA-1; SHA-256 for RSA-KEM]
Advanced options. See Cms.EnvDataOptions.
Key derivation function (KDF) for ECDH key agreement scheme (where applicable)
Key wrap algorithm for ECDH key agreement scheme (default=match content encryption algorithm)
(formerly ukmString
) Use to pass optional additional
user key material (ukm) for KDF where KeyAgreement (kari) type or
RSA-KEM is used. Or use to pass the password for a pwri type or the key
encryption key (KEK) for a kekri type. Either pass a plain ASCII string,
e.g. "abc"
or use the format
"#x<hex-digits>"
to pass a string of arbitrary octet
values, e.g. "#xdeadbeef01"
to pass the 5 bytes
0xde,0xad,0xbe,0xef,0x01
. Optional for kari types but
required for pwri and kekri types.
Optional iteration count for KDF in pwri type (default=4096) or tag length for AuthEnvelopedData (in range 12-16, default=16). Otherwise ignored.
Alternative way to specify content encryption algorithm with more
options. Takes precedence over cipherAlg
.
[default=AES128-CBC]
Int32
Number of successful recipients or negative error code
Cms Class
CryptoSysPKI Namespace
Create a CMS object of type SignedData from an input data file (advanced options including RSA-PSS).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
MakeSigData(String, String, String, String, Cms.SigAlg, Cms.SigDataOptions) | Create a CMS object of type SignedData from an input data file (advanced options including RSA-PSS). |
MakeSigData(String, String, String, String, HashAlgorithm, Cms.SigDataOptions) | Create a CMS object of type SignedData from an input data file using RSASSA-PKCS1V1_5 with options. |
public static int MakeSigData(
string outputFile,
string inputFile,
string certList,
string privateKey,
.SigAlg sigAlg,
Cms.SigDataOptions advOptions = Cms.SigDataOptions.Default
Cms)
name of output file to be created
name of file containing message data to be signed
filename of the signer’s certificate and (optionally) a list of other certificates to be included in the output, separated by semi-colons (;) Alternatively specify a single PKCS#7 certificate chain file (.p7c/.p7b) containing the signer’s certificate.
private key data for the sender
Signature algorithm.
Advanced option flags. See Cms.SigDataOptions.
Int32
Zero if successful; otherwise it returns an error code
= Rsa.ReadPrivateKey("AlicePrivRSASign.p8e", "password");
StringBuilder sbPrivateKey string fnameOutput = "BasicSignByAlice.bin";
string fnameInput = "excontent.txt";
string fnameCert = "AliceRSASignByCarl.cer";
int n = Cms.MakeSigData(fnameOutput, fnameInput, fnameCert, sbPrivateKey.ToString(), Cms.SigAlg.Default, 0);
Cms Class
CryptoSysPKI Namespace
Create a CMS object of type SignedData from an input data file using RSASSA-PKCS1V1_5 with options.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
MakeSigData(String, String, String, String, Cms.SigAlg, Cms.SigDataOptions) | Create a CMS object of type SignedData from an input data file (advanced options including RSA-PSS). |
MakeSigData(String, String, String, String, HashAlgorithm, Cms.SigDataOptions) | Create a CMS object of type SignedData from an input data file using RSASSA-PKCS1V1_5 with options. |
public static int MakeSigData(
string outputFile,
string inputFile,
string certList,
string privateKey,
= HashAlgorithm.Sha1,
HashAlgorithm hashAlg .SigDataOptions advOptions = Cms.SigDataOptions.Default
Cms)
name of output file to be created
name of file containing message data to be signed
filename of the signer’s certificate and (optionally) a list of other certificates to be included in the output, separated by semi-colons (;) Alternatively specify a single PKCS#7 certificate chain file (.p7c/.p7b) containing the signer’s certificate.
private key data for the sender
Message digest algorithm to be used in signature [default=SHA-1].
Advanced option flags. See Cms.SigDataOptions.
Int32
Zero if successful; otherwise it returns an error code
RSASSA-PKCS1V1_5 only.
Cms Class
CryptoSysPKI Namespace
Create a CMS object of type SignedData from an array of bytes.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int MakeSigDataFromBytes(
string outputFile,
byte[] inputData,
string certList,
string privateKey,
.SigAlg sigAlg,
Cms.SigDataOptions advOptions
Cms)
name of output file to be created.
message data to be signed in a byte array.
filename of the signer’s certificate and (optionally) a list of other certificates to be included in the output, separated by semi-colons (;) Alternatively specify a single PKCS#7 certificate chain file (.p7c/.p7b) containing the signer’s certificate.
Private key data for the sender.
Signature algorithm.
Advanced option flags. See Cms.SigDataOptions.
Int32
Zero if successful; otherwise it returns an error code
Cms Class
CryptoSysPKI Namespace
Create a SignedData object from a “pseudo” object.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int MakeSigDataFromPseudo(
string outputFile,
string inputPseudoFile,
byte[] sigValue,
.Format format = Cms.Format.Default
Cms)
Name of output file to be created.
Input “pseudo” file with dummy placeholder signature.
Signature value computed by external service.
Output format (default = binary)
Int32
Zero if successful; otherwise it returns an error code
RSASSA-PKCS1V1_5 only.
Cms Class
CryptoSysPKI Namespace
Create a CMS object of type SignedData using a pre-computed signature (advanced algorithms).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int MakeSigDataFromSigValue(
string outputFile,
byte[] sigValue,
byte[] contentData,
string certList,
= HashAlgorithm.Sha1,
HashAlgorithm hashAlg .SigDataOptions advOptions = Cms.SigDataOptions.Default
Cms)
name of output file to be created
signature value
string containing content data that has been signed
filename of the signer’s certificate and (optionally) a list of other certificates to be included in the output, separated by semi-colons (;) Alternatively specify a single PKCS#7 certificate chain file (.p7c/.p7b) containing the signer’s certificate.
Message digest algorithm to be used in signature [default=SHA-1]
Advanced option flags. See Cms.SigDataOptions.
Int32
Zero if successful; otherwise it returns an error code
RSASSA-PKCS1V1_5 only.
Cms Class
CryptoSysPKI Namespace
Create a CMS object of type SignedData from an input string (advanced options including RSA-PSS).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
MakeSigDataFromString(String, String, String, String, Cms.SigAlg, Cms.SigDataOptions) | Create a CMS object of type SignedData from an input string (advanced options including RSA-PSS). |
MakeSigDataFromString(String, String, String, String, HashAlgorithm, Cms.SigDataOptions) | Create a CMS object of type SignedData from an input string using RSASSA-PKCS1V1_5 with options. |
public static int MakeSigDataFromString(
string outputFile,
string inputData,
string certList,
string privateKey,
.SigAlg sigAlg,
Cms.SigDataOptions advOptions = Cms.SigDataOptions.Default
Cms)
name of output file to be created
string containing message data to be signed
filename of the signer’s certificate and (optionally) a list of other certificates to be included in the output, separated by semi-colons (;) Alternatively specify a single PKCS#7 certificate chain file (.p7c/.p7b) containing the signer’s certificate.
private key data for the sender
Signature algorithm.
Advanced option flags. See Cms.SigDataOptions.
Int32
Zero if successful; otherwise it returns an error code
Cms Class
CryptoSysPKI Namespace
Create a CMS object of type SignedData from an input string using RSASSA-PKCS1V1_5 with options.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
MakeSigDataFromString(String, String, String, String, Cms.SigAlg, Cms.SigDataOptions) | Create a CMS object of type SignedData from an input string (advanced options including RSA-PSS). |
MakeSigDataFromString(String, String, String, String, HashAlgorithm, Cms.SigDataOptions) | Create a CMS object of type SignedData from an input string using RSASSA-PKCS1V1_5 with options. |
public static int MakeSigDataFromString(
string outputFile,
string inputData,
string certList,
string privateKey,
= HashAlgorithm.Sha1,
HashAlgorithm hashAlg .SigDataOptions advOptions = Cms.SigDataOptions.Default
Cms)
name of output file to be created
string containing message data to be signed
filename of the signer’s certificate and (optionally) a list of other certificates to be included in the output, separated by semi-colons (;) Alternatively specify a single PKCS#7 certificate chain file (.p7c/.p7b) containing the signer’s certificate.
private key data for the sender
Message digest algorithm to be used in signature [default=SHA-1]
Advanced option flags. See Cms.SigDataOptions.
Int32
Zero if successful; otherwise it returns an error code
RSASSA-PKCS1V1_5 only.
Cms Class
CryptoSysPKI Namespace
Query a CMS enveloped-data object file for selected information.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string QueryEnvData(
string inputFile,
string query
)
file containing CMS enveloped-data object
Query string (case insensitive)
String
String containing the result or an empty string if not found or
error.
Valid queries are:
"version" |
envelopedData CMSVersion (edVer ) value,
e.g. "0" . |
---|---|
"recipientInfoVersion" |
recipientInfo version (riVer ) value. |
"recipientInfoType" |
Type of recipientInfo, e.g. ktri , kari ,
… |
"CountOfRecipientInfos" |
Number of RecipientInfos included in the data. |
"recipientIssuerName" |
Distinguished Name of recipient’s certificate issuer. |
"recipientSerialNumber" |
serialNumber of recipient’s certificate in hex format |
"keyEncryptionAlgorithm" |
keyEncryptionAlgorithm, e.g. "rsaEncryption" . |
"keyEncryptionFlags" |
Bit flags used for the key encryption algorithm (ktri only). |
"SizeOfEncryptedKey" |
Size (in bytes) of the EncryptedKey. |
"encryptedKey" |
EncryptedKey value encoded in hex. |
"oaepParams" |
Parameters used for RSA-OAEP (if applicable). |
"keyWrapAlgorithm" |
Key wrap algorithm, e.g. "aes128-wrap" (kari and kekri
only). |
"originatorKeyAlgorithm" |
OriginatorPublicKey algorithm, e.g. "ecPublicKey" (kari
only). |
"originatorPublicKey" |
OriginatorPublicKey publicKey value encoded in hex (kari only). |
"keyid" |
keyIdentifier for KEKRecipientInfo (kekri) type. |
"contentEncryptionAlgorithm" |
contentEncryptionAlgorithm, e.g. "des-EDE3-CBC" . |
"SizeOfEncryptedContent" |
Size (in bytes) of the EncryptedContent. |
"encryptedContent" |
EncryptedContent encoded in hex. |
"iv" |
Initialization vector encoded in hex. |
By default, the function queries the first recipientInfo in the file.
To query the Nth recipientInfo append "/N"
to the query
string, e.g. "recipientInfoVersion/2"
to find the version
number of the second recipientInfo in the file.
Cms Class
CryptoSysPKI Namespace
Query a CMS signed-data object for selected information.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string QuerySigData(
string inputFile,
string query
)
file containing CMS signed-data object
Query string (case insensitive)
String
String containing the result or an empty string if not found or
error.
Valid queries are:
"version" |
signedData version (sdVer) value, e.g. "1" . |
---|---|
"eContentType" |
ContentType of the EncapsulatedContentInfo,
e.g. "data" . |
"HASeContent" |
“1” if eContent is present; “0” if not. |
"CountOfCertificates" |
Number of certificates included in the data. |
"CountOfSignerInfos" |
Number of SignerInfos included in the data. |
"signerInfoVersion" |
signerInfo version (siVer) value. |
"digestAlgorithm" |
digestAlgorithm, e.g. "sha1" . |
"signatureAlgorithm" |
signatureAlgorithm, e.g. "rsaEncryption" . |
"signatureValue" |
Signature value encoded in hex. |
"HASsignedAttributes" |
“1” if signedAttributes (authenticatedAttributes) are present; “0” if not. |
"DigestOfSignedAttrs" |
Computed digest over signed attributes, if present, using digestAlgorithm. |
"DigestOfeContent" |
Computed digest over eContent, if present, using digestAlgorithm. |
"signingTime" |
signingTime attribute in format
"2005-12-31 23:30:59" |
"messageDigest" |
messageDigest attribute in hexadecimal format, if present |
"pssParams" |
Parameters used for RSA-PSS (if applicable). |
"HASsigningCertificate" |
“1” if an ESS signingCertificate is present; “0” if not. |
"signingCertHash" |
certHash value of ESS signing certificate, if present, encoded in hex. |
"HASalgorithmProtection" |
“1” if a cmsAlgorithmProtection attribute is present; “0” if not. |
By default, the function queries the first signerInfo in the file. To
query the Nth signerInfo append "/N"
to the query string,
e.g. "signerInfoVersion/2"
to find the version number of
the second signerInfo in the file.
Cms Class
CryptoSysPKI Namespace
Read and extract the decompressed contents of a CMS compressed-data file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int ReadComprData(
string outputFile,
string inputFile,
.ComprDataOptions opts
Cms)
Output file to be created
Input data file
Options [default=inflate contents]
Int32
If successful the return value is the number of bytes in the output
file; otherwise it returns a non-zero error code
Cms Class
CryptoSysPKI Namespace
Read and decrypt a CMS enveloped-data object to a byte array.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] ReadEnvDataToBytes(
string inputFile,
string x509File,
string privateKey
)
Name of file containing CMS enveloped-data object (binary or base64-encoded) or the data as a base64 or PEM string.
(optional) filename of the recipient’s X.509 certificate.
Internal representation of private key.
Byte[]
Decrypted content in a byte array, or empty array on error.
// Read in content to a byte array
byte[] b = Cms.ReadEnvDataToBytes(inputFile, "", privateKey);
// Convert to a .NET string (assuming UTF-8 encoded)
string s = System.Text.Encoding.UTF8.GetString(b);
Cms Class
CryptoSysPKI Namespace
Read and decrypt a CMS enveloped-data object to a file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int ReadEnvDataToFile(
string outputFile,
string inputFile,
string x509File,
string privateKey,
.ReadOptions opts = Cms.ReadOptions.None
Cms)
Name of output file to be created.
Name of file containing CMS enveloped-data object (binary or base64-encoded) or the data as a base64 or PEM string.
(optional) filename of the recipient’s X.509 certificate.
Internal representation of private key.
Use Cms.ReadOptions for faster handling of large files (binary only).
Int32
Zero if successful; otherwise it returns an error code.
Cms Class
CryptoSysPKI Namespace
Read and decrypt a CMS enveloped-data object to a string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string ReadEnvDataToString(
string inputFile,
string x509File,
string privateKey
)
Name of file containing CMS enveloped-data object (binary or base64-encoded) or the data as a base64 or PEM string.
(optional) filename of the recipient’s X.509 certificate
Internal representation of private key.
String
Decrypted content in a string or empty string on error.
Use this only when the decrypted text is known to be plain ASCII text, otherwise use ReadEnvDataToBytes.
Cms Class
CryptoSysPKI Namespace
Read the content from a CMS signed-data object directly into a byte array.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] ReadSigDataToBytes(
string inputFile
)
Name of file containing CMS signed-data object (binary or base64-encoded) or the data as a base64 or PEM string.
Byte[]
Byte array containing the content or a zero-length array if error.
Use this if the content contains non-ASCII characters, e.g. UTF-8 encoded.
// Read in content to a byte array
byte[] b = Cms.ReadSigDataToBytes(inputFile);
// Convert to a .NET string (assumed UTF-8 encoded)
string s = System.Text.Encoding.UTF8.GetString(b);
Cms Class
CryptoSysPKI Namespace
Read the content from a CMS signed-data object file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int ReadSigDataToFile(
string outputFile,
string inputFile,
.ReadOptions opts = Cms.ReadOptions.None
Cms)
file to receive content
Name of file containing CMS signed-data object (binary or base64-encoded) or the data as a base64 or PEM string.
Option flags: set as zero for defaults.
Int32
If successful, the return value is a positive number indicating the
number of bytes in the content; otherwise it returns a negative error code.
Cms Class
CryptoSysPKI Namespace
Read the content from a CMS signed-data object directly into a string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string ReadSigDataToString(
string inputFile
)
Name of file containing CMS signed-data object (binary or base64-encoded) or the data as a base64 or PEM string.
String
String containing the content or an empty string if error
Cms Class
CryptoSysPKI Namespace
Verify the signature and content of a signed-data CMS object file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int VerifySigData(
string inputFile,
string certFile = "",
string hexDigest = "",
.SigDataOptions advOptions = Cms.SigDataOptions.Default
Cms)
file containing CMS signed-data object
an (optional) X.509 certificate file of the signer
(optional) digest of eContent to be verified (use for “detached-signature” form)
Use for BigFile
option, otherwise ignored
Int32
Zero if successfully verified; otherwise it returns a non-zero error code
Cms Class
CryptoSysPKI Namespace
Character conversion routines
System.Object
CryptoSysPKI.Cnv
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Cnv
The Cnv type exposes the following members.
Name | Description |
---|---|
Base64Filter | Filter non-base64 characters from a string. |
Base64FromHex | Convert hexadecimal-encoded data into base64-encoded data. |
ByteEncoding | Convert encoding of byte array between UTF-8 and Latin-1. |
CheckUTF8 | Check that a byte array contains only valid UTF-8 encoded characters. |
CheckUTF8File | Check that a file contains only valid UTF-8 encoded characters. |
FromBase58 | Convert a base58-encoded string to an equivalent array of 8-bit unsigned integers. |
FromBase64 | Convert a base64-encoded string to an equivalent array of 8-bit unsigned integers. |
FromHex | Convert the specified string representation of a value consisting of hexadecimal (base 16) digits to an equivalent array of 8-bit unsigned integers. |
HexFilter | Filter non-hexadecimal characters from a string. |
HexFromBase64 | Convert base64-encoded data into hexadecimal-encoded data. |
NumFromBytes | Convert the leftmost four bytes of an array to an unsigned 32-bit integer. |
NumToBytes | Convert a 32-bit integer to an array of 4 bytes. |
ReverseBytes | Reverse the order of a byte array. |
ShortPathName | Retrieve the Windows short path form of the specified path. |
StringFromBase64 | Convert a base64-encoded string into a text string. |
StringFromHex | Convert a hexadecimal-encoded string into a text string. |
ToBase58 | Convert 8-bit binary data to equivalent base58-encoded string format. |
ToBase64(Byte[]) | Convert 8-bit binary data to equivalent base64-encoded string format. |
ToBase64(String) | Convert a string of ANSI characters to equivalent base64-encoded string format. |
ToHex(Byte[]) | Convert 8-bit binary data to equivalent hexadecimal string format. |
ToHex(String) | Converts a string of ANSI characters to equivalent hexadecimal string format |
Filter non-base64 characters from a string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string Base64Filter(
string s
)
String to be filtered
String
Filtered string
Valid base64 characters are [0-9A-Za-z+/=]
Cnv Class
CryptoSysPKI Namespace
Convert hexadecimal-encoded data into base64-encoded data.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string Base64FromHex(
string s
)
Hex-encoded data
String
Base64-encoded data
Cnv Class
CryptoSysPKI Namespace
Convert encoding of byte array between UTF-8 and Latin-1.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] ByteEncoding(
byte[] data,
.EncodingConversion direction
Cnv)
Input data to be converted
Direction of conversion
Byte[]
Converted data (or empty array on error)
Converting UTF-8 from Latin-1 assumes the input is from the 8-bit Latin-1 character set and so will always produce output that is valid UTF-8. However, for Latin-1 from UTF-8, the input must contain a valid sequence of UTF-8-encoded bytes and this must be convertible to a single-byte character set, or an error will be returned.
Cnv Class
CryptoSysPKI Namespace
Check that a byte array contains only valid UTF-8 encoded characters.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int CheckUTF8(
byte[] b
)
input byte array to check
Int32
Zero if the encoded bytes is invalid UTF-8, or a positive number if the input contains valid UTF-8 data, where the value of the number indicates the nature of the encoded characters:
0 | Not valid UTF-8 |
---|---|
1 | Valid UTF-8, all chars are 7-bit ASCII |
2 | Valid UTF-8, contains at least one multi-byte character equivalent to 8-bit ANSI |
3 | Valid UTF-8, contains at least one multi-byte character that cannot be represented in a single-byte character set |
‘Overlong’ UTF-8 sequences and illegal surrogates are rejected as invalid.
Cnv Class
CryptoSysPKI Namespace
Check that a file contains only valid UTF-8 encoded characters.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int CheckUTF8File(
string fileName
)
name of file to check
Int32
Zero if the encoded bytes is invalid UTF-8, or a positive number if the input contains valid UTF-8 data, where the value of the number indicates the nature of the encoded characters:
0 | Not valid UTF-8 |
---|---|
1 | Valid UTF-8, all chars are 7-bit ASCII |
2 | Valid UTF-8, contains at least one multi-byte character equivalent to 8-bit ANSI |
3 | Valid UTF-8, contains at least one multi-byte character that cannot be represented in a single-byte character set |
‘Overlong’ UTF-8 sequences and illegal surrogates are rejected as invalid.
Cnv Class
CryptoSysPKI Namespace
Convert a base58-encoded string to an equivalent array of 8-bit unsigned integers.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] FromBase58(
string s
)
Base58-encoded data
Byte[]
Data as array of bytes
This uses the “Bitcoin” scheme of base58 encoding where the leading character ‘1’ is reserved for representing an entire leading zero byte.
Cnv Class
CryptoSysPKI Namespace
Convert a base64-encoded string to an equivalent array of 8-bit unsigned integers.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] FromBase64(
string s
)
Base64-encoded data
Byte[]
Binary data in byte array, or an empty array on error.
Whitespace characters are ignored, but other non-base64 characters will cause an error.
Cnv Class
CryptoSysPKI Namespace
Convert the specified string representation of a value consisting of hexadecimal (base 16) digits to an equivalent array of 8-bit unsigned integers.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] FromHex(
string s
)
Hex-encoded string
Byte[]
Binary data in byte array, or an empty array on error.
Whitespace and ASCII punctuation characters are ignored, but other non-hex characters will cause an error.
Cnv Class
CryptoSysPKI Namespace
Filter non-hexadecimal characters from a string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string HexFilter(
string s
)
Input string to be filtered
String
Filtered string
Cnv Class
CryptoSysPKI Namespace
Convert base64-encoded data into hexadecimal-encoded data.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string HexFromBase64(
string s
)
Base64-encoded data
String
Hex-encoded data
Cnv Class
CryptoSysPKI Namespace
Convert the leftmost four bytes of an array to an unsigned 32-bit integer.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static uint NumFromBytes(
byte[] b,
.EndianNess endn = Cnv.EndianNess.BigEndian
Cnv)
Byte array to be converted
Byte order
UInt32
Integer value
An array shorter than 4 bytes will be padded on the right with zeros
byte[] b = new byte[4] { 0xde, 0xad, 0xbe, 0xef };
uint nb = Cnv.NumFromBytes(b, Cnv.EndianNess.BigEndian);
.WriteLine("0x" + nb.ToString("x8")); // 0xdeadbeef
Consoleuint nl = Cnv.NumFromBytes(b, Cnv.EndianNess.LittleEndian);
.WriteLine("0x" + nl.ToString("x8")); // 0xefbeadde Console
Cnv Class
CryptoSysPKI Namespace
Convert a 32-bit integer to an array of 4 bytes.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] NumToBytes(
uint n,
.EndianNess endn = Cnv.EndianNess.BigEndian
Cnv)
Integer to be converted
Byte order
Byte[]
Byte array containing representation of integer in given order
byte[] bb = Cnv.NumToBytes(0xdeadbeef, Cnv.EndianNess.BigEndian);
.WriteLine(Cnv.ToHex(bb)); // DEADBEEF
Consolebyte[] bl = Cnv.NumToBytes(0xdeadbeef, Cnv.EndianNess.LittleEndian);
.WriteLine(Cnv.ToHex(bl)); // EFBEADDE Console
Cnv Class
CryptoSysPKI Namespace
Reverse the order of a byte array.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] ReverseBytes(
byte[] data
)
Input data to be reversed
Byte[]
Byte array in reverse order
Cnv Class
CryptoSysPKI Namespace
Retrieve the Windows short path form of the specified path.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string ShortPathName(
string pathName
)
File path name.
String
Windows short path name of file or the empty string if file does not
exist.
Windows platforms only. The file path must exist. The short path name is guaranteed to be ASCII.
Cnv Class
CryptoSysPKI Namespace
Convert a base64-encoded string into a text string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string StringFromBase64(
string s
)
Base64-encoded data
String
String value
Uses the ‘Default’ encoding for the system’s current ANSI code page. This assumes the user knows the resulting characters are all printable.
Cnv Class
CryptoSysPKI Namespace
Convert a hexadecimal-encoded string into a text string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string StringFromHex(
string s
)
Hex-encoded data
String
String value
Uses the ‘Default’ encoding for the system’s current ANSI code page, usually code page 1252 (similar to Latin-1). This assumes the user knows the resulting characters are all printable.
Cnv Class
CryptoSysPKI Namespace
Convert 8-bit binary data to equivalent base58-encoded string format.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string ToBase58(
byte[] binaryData
)
binary data
String
Base58-encoded string
This uses the “Bitcoin” scheme of base58 encoding where the leading character ‘1’ is reserved for representing an entire leading zero byte.
Cnv Class
CryptoSysPKI Namespace
Convert 8-bit binary data to equivalent base64-encoded string format.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
ToBase64(Byte[]) | Convert 8-bit binary data to equivalent base64-encoded string format. |
ToBase64(String) | Convert a string of ANSI characters to equivalent base64-encoded string format. |
public static string ToBase64(
byte[] binaryData
)
binary data
String
Base64-encoded string
Cnv Class
CryptoSysPKI Namespace
Convert a string of ANSI characters to equivalent base64-encoded string format.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
ToBase64(Byte[]) | Convert 8-bit binary data to equivalent base64-encoded string format. |
ToBase64(String) | Convert a string of ANSI characters to equivalent base64-encoded string format. |
public static string ToBase64(
string s
)
String of data to be encoded
String
Base64-encoded data
Uses the ‘Default’ encoding for the system’s current ANSI code page
Cnv Class
CryptoSysPKI Namespace
Convert 8-bit binary data to equivalent hexadecimal string format.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
ToHex(Byte[]) | Convert 8-bit binary data to equivalent hexadecimal string format. |
ToHex(String) | Converts a string of ANSI characters to equivalent hexadecimal string format |
public static string ToHex(
byte[] binaryData
)
binary data in byte array
String
Hex-encoded string.
Cnv Class
CryptoSysPKI Namespace
Converts a string of ANSI characters to equivalent hexadecimal string format
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
ToHex(Byte[]) | Convert 8-bit binary data to equivalent hexadecimal string format. |
ToHex(String) | Converts a string of ANSI characters to equivalent hexadecimal string format |
public static string ToHex(
string s
)
String of data to be encoded
String
Hex-encoded data
Uses the ‘Default’ encoding for the system’s current ANSI code page
Cnv Class
CryptoSysPKI Namespace
Compression utilities
System.Object
CryptoSysPKI.Compr
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Compr
The Compr type exposes the following members.
Name | Description |
---|---|
Compress | Compress data using zlib compression. |
Uncompress | Uncompress data using zlib compression. |
Compress data using zlib compression.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] Compress(
byte[] data
)
Data to be compressed.
Byte[]
Compressed data, or an empty array on error.
Compr Class
CryptoSysPKI Namespace
Uncompress data using zlib compression.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] Uncompress(
byte[] data
)
Compressed data to be uncompressed.
Byte[]
Uncompressed data, or an empty array on error.
An empty array may also be returned if the original data was the empty array itself.
Compr Class
CryptoSysPKI Namespace
Elliptic curve cryptography
System.Object
CryptoSysPKI.Ecc
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Ecc
The Ecc type exposes the following members.
Name | Description |
---|---|
DHSharedSecret | Compute EC Diffie-Hellman (ECDH) shared secret. |
KeyHashCode | Compute the hash code of an “internal” ECC public or private key string. |
MakeKeys | Generate an EC public/private key pair and save as two key files. |
PublicKeyFromPrivate | Convert an internal EC private key string into an internal EC public key string. |
QueryKey | Query an EC key string for selected information. |
ReadKeyByCurve | Read an EC key from its hexadecimal representation with options for safe curves. |
ReadPrivateKey | Read from a file or string containing an EC private key into an “internal” private key string. |
ReadPublicKey | Read from a file or string containing an EC public key into an “internal” public key string. |
SaveEncKey | Save an internal EC private key string to an encrypted private key file. |
SaveKey | Save an internal EC key string (public or private) to an unencrypted key file. |
Compute EC Diffie-Hellman (ECDH) shared secret.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] DHSharedSecret(
string ourIntPrivateKey,
string theirIntPublicKey
)
Our own private key in ephemeral “internal” form.
Other party’s public key in “internal” form.
Byte[]
The Diffie-Hellman shared secret.
Ecc Class
CryptoSysPKI Namespace
Compute the hash code of an “internal” ECC public or private key string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int KeyHashCode(
string intKeyString
)
Internal key string
Int32
A 32-bit hash code for the key, or zero on error.
Should be the same for a matching private and public key.
Ecc Class
CryptoSysPKI Namespace
Generate an EC public/private key pair and save as two key files.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int MakeKeys(
string publicKeyfile,
string privateKeyFile,
.CurveName curveName,
Eccstring password,
.PbeScheme pbes = Ecc.PbeScheme.Default,
Eccstring paramString = "",
.Format fileFormat = Ecc.Format.Default
Ecc)
name of public key file to be created
name of encrypted private key file to be created
name of elliptic curve
password to be used for the encrypted key file.
(optional) Password-based encryption scheme to encrypt private key
[default = pbeWithSHAAnd3-KeyTripleDES-CBC
]
Optional parameters. A set of attribute name=value pairs separated by a semicolon “;” (see remarks).
(optional) Format to save file [default = DER binary]
Int32
Zero if successful or non-zero error
code
Valid name-value pairs for paramString
are:
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;" . |
Valid values for hmac-name are one of
{hmacWithSHA1, hmacWithSHA224, hmacWithSHA256, hmacWithSHA384, hmacWithSHA512}
.
// All default settings...
= Ecc.MakeKeys(pubkeyfile, prikeyfile, Ecc.CurveName.Prime192v1, "password");
n // With specialist options...
= Ecc.MakeKeys(pubkeyfile, prikeyfile, Ecc.CurveName.Prime192v1, "password",
n .PbeScheme.Pbe_Pbkdf2_aes128_CBC, "count=3999;prf=hmacWithSha256", Ecc.Format.PEM); Ecc
Ecc Class
CryptoSysPKI Namespace
Convert an internal EC private key string into an internal EC public key string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string PublicKeyFromPrivate(
string internalKey
)
the private key as an internal key string
String
The public key in ephemeral “internal” representation, or the empty
string on error
Ecc Class
CryptoSysPKI Namespace
Query an EC key string for selected information.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string QueryKey(
string internalKey,
string query
)
containing the key as an internal key string
Query string (case insensitive)
String
String containing the result or an empty string if not found or
error.
Valid queries are:
"curveName" |
Name of the curve. |
---|---|
"keyBits" |
Number of bits in the key. |
"isPrivate" |
“1” if key is a private key; “0” if not. |
"privateKey" |
Value of the private key in hex format. |
"publicKey" |
Value of the public key in hex format. |
Ecc Class
CryptoSysPKI Namespace
Read an EC key from its hexadecimal representation with options for safe curves.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string ReadKeyByCurve(
string hexKey,
.CurveName curveName,
Ecc.KeyType keyType = Ecc.KeyType.Default
Ecc)
hexadecimal representation of the key, private or public
name of the elliptic curve
(optional) Specify PrivateKey
or PublicKey
(safe curves Ed25519 and X25519 only, otherwise ignored)
String
The key in ephemeral “internal” representation, or the empty string on
error
The safe curves Ed25519 and X25519 have the same length for both private and public keys, so, for these safe curves, you must specify whether the key value represents a public or a private key.
Ecc Class
CryptoSysPKI Namespace
Read from a file or string containing an EC private key into an “internal” private key string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static StringBuilder ReadPrivateKey(
string keyFileOrString,
string password = ""
)
Name of private key file or a PEM String containing the key
Password for private key, if encrypted; or ""
if not
StringBuilder
StringBuilder containing an internal representation of the private key;
or an empty StringBuilder if error
This returns a StringBuilder, not a string, to allow secure wiping. Use sb.ToString() to obtain a string. Use Wipe.String(sb) to clear.
Ecc Class
CryptoSysPKI Namespace
Zeroise a StringBuilder.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static bool String(
StringBuilder sb)
StringBuilder to be wiped
Boolean
true
if successful; false
if fails
NB You can’t wipe an ordinary string as they are immutable in C#, so store any sensitive string data in a StringBuilder.
= Rsa.ReadPrivateKey("BobPrivRSAEncrypt.p8e", "password");
StringBuilder sbPrivateKey .WriteLine("Before Wipe.String, sbPrivateKey contains {0} characters.", sbPrivateKey.Length);
Console.String(sbPrivateKey);
Wipe.WriteLine("After Wipe.String, sbPrivateKey = [{0}]", sbPrivateKey.ToString());
Console// Before Wipe.String, sbPrivateKey contains 848 characters.
// After Wipe.String, sbPrivateKey = []
Wipe Class
CryptoSysPKI Namespace
Read from a file or string containing an EC public key into an “internal” public key string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static StringBuilder ReadPublicKey(
string keyFileOrString
)
Name of public key file or a PEM String containing the key
StringBuilder
StringBuilder containing an internal representation of the public key;
or an empty StringBuilder if error
This returns a StringBuilder, not a string. Use sb.ToString() to obtain a string.
Ecc Class
CryptoSysPKI Namespace
Save an internal EC private key string to an encrypted private key file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int SaveEncKey(
string outputFile,
string internalKey,
string password,
.PbeScheme pbes,
Eccstring paramString,
.Format fileFormat
Ecc)
name of key file to be created
the private key in an internal key string
the password to be used for the encrypted key file
Password-based encryption scheme to encrypt private key [default =
pbeWithSHAAnd3-KeyTripleDES-CBC
]
Optional parameters. A set of attribute name=value pairs separated by
a semicolon “;” (see remarks). Set as ""
for defaults.
Format to save file [default = DER binary]
Int32
Zero if successful or non-zero error
code
Valid name-value pairs for paramString
are:
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 ]. |
Valid values for hmac-name are one of
{hmacWithSHA1, hmacWithSHA224, hmacWithSHA256, hmacWithSHA384, hmacWithSHA512}
.
Ecc Class
CryptoSysPKI Namespace
Save an internal EC key string (public or private) to an unencrypted key file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int SaveKey(
string outputFile,
string internalKey,
.KeyType keyType = Ecc.KeyType.Default,
Ecc.Format fileFormat = Ecc.Format.Default
Ecc)
Name of key file to be created
the private or public EC key in an internal key string
Key structure for private key (ignored for public)
Format to save file [default = DER binary]
Int32
If successful, the return value is zero; otherwise it returns a nonzero
error code
Ecc Class
CryptoSysPKI Namespace
General info about the core DLL and errors returned by it.
System.Object
CryptoSysPKI.General
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class General
The General type exposes the following members.
Name | Description |
---|---|
CompileTime | Return date and time the core CryptoSys PKI DLL was last compiled. |
ErrorCode | Return the error code of the first error that occurred when calling the last function. |
ErrorLookup | Return a description of an error code. |
FormatErrorMessage | Return an error message string for the last error. |
LastError | Retrieve the last error message set by the toolkit. |
LicenceType | Return licence type. |
ModuleInfo | Get additional information about the core DLL module. |
ModuleName | Return full path name of core CryptoSys PKI DLL module. |
NetVersion | Return the version of this .NET module. |
Platform | Return the platform the core DLL was compiled for. |
PowerUpTests | Perform FIPS-140-2 start-up tests. |
Version | Return the release version of the core CryptoSys PKI DLL as an integer value. |
Return date and time the core CryptoSys PKI DLL was last compiled.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string CompileTime()
String
Date and time string
string s = CryptoSysPKI.General.CompileTime();
.WriteLine("CompileTime={0}", s); Console
General Class
CryptoSysPKI Namespace
Return an error message string for the last error.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string FormatErrorMessage(
int errCode = 0,
string userMsg = ""
)
Error code returned by last call (optional)
Optional message string
String
Error message as a string Error (errCode) ...
General Class
CryptoSysPKI Namespace
Retrieve the last error message set by the toolkit.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string LastError()
String
Final error message from last call (may be empty)
General Class
CryptoSysPKI Namespace
Return licence type.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static char LicenceType()
Char
D=Developer T=Trial
char ch = CryptoSysPKI.General.LicenceType();
.WriteLine("LicenceType={0}", ch); Console
General Class
CryptoSysPKI Namespace
Get additional information about the core DLL module.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string ModuleInfo()
String
Additional information, e.g. “Licensed Developer Edition”.
General Class
CryptoSysPKI Namespace
Return full path name of core CryptoSys PKI DLL module.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string ModuleName()
String
File name.
If using the Win32 DLL in the system folder on a 64-bit system,
Windows will return "C:\WINDOWS\SYSTEM32\diCrPKI.dll"
when
the DLL file path is actually
"C:\WINDOWS\SYSWOW64\diCrPKI.dll"
. Use General.Platform() to find out exactly
which DLL is being used.
string s = CryptoSysPKI.General.ModuleName();
.WriteLine("ModuleName={0}", s); Console
General Class
CryptoSysPKI Namespace
Return the version of this .NET module.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string NetVersion()
String
Version string, e.g. "20.1.0"
General Class
CryptoSysPKI Namespace
Return the platform the core DLL was compiled for.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string Platform()
String
"Win32"
or "X64"
General Class
CryptoSysPKI Namespace
Perform FIPS-140-2 start-up tests.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int PowerUpTests()
Int32
Zero on success
General Class
CryptoSysPKI Namespace
Return the release version of the core CryptoSys PKI DLL as an integer value.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int Version()
Int32
Version number in form Major * 10000 + Minor * 100 + Release. For
example, version 3.10.1 would return 31001.
int n = CryptoSysPKI.General.Version();
.WriteLine("Version={0}", n); Console
General Class
CryptoSysPKI Namespace
Message Digest Hash Functions
System.Object
CryptoSysPKI.Hash
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Hash
The Hash type exposes the following members.
Name | Description |
---|---|
BytesFromBytes | Create hash digest in byte format of byte input. |
BytesFromFile | Create hash digest of a binary file. |
Double | Create double hash, i.e. hash of hash, in byte format of byte input. |
HexFromBytes | Create hash digest in hex format of byte input. |
HexFromFile | Create hash digest in hex format of a binary file. |
HexFromHex | Create hash digest in hex format of hex-encoded input. |
HexFromString | Create hash digest in hex format of string input. |
HexFromTextFile | Create hash digest in hex format of a text file, treating CR-LF (0x13, 0x10) pairs as a single LF (0x10). |
Length | Return length of message digest output in bytes. |
Create hash digest in byte format of byte input.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] BytesFromBytes(
byte[] message,
HashAlgorithm hashAlg)
Message data in byte format
Hash algorithm to be used
Byte[]
Message digest in byte format
byte[] m = { 0x61, 0x62, 0x63 }; // "abc" in byte array
byte[] h = Hash.BytesFromBytes(m, HashAlgorithm.Sha256);
.WriteLine("SHA-256(b'abc')=\n" + h.ToHex());
Console// BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD
Hash Class
CryptoSysPKI Namespace
Create hash digest of a binary file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] BytesFromFile(
string fileName,
HashAlgorithm hashAlg)
Name of file containing message data
Hash algorithm to be used
Byte[]
Message digest in byte format
Hash Class
CryptoSysPKI Namespace
Create double hash, i.e. hash of hash, in byte format of byte input.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] Double(
byte[] message,
HashAlgorithm hashAlg)
Message data in byte format
Hash algorithm to be used
Byte[]
Message digest HASH(HASH(m))
in byte format
Hash Class
CryptoSysPKI Namespace
Create hash digest in hex format of byte input.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string HexFromBytes(
byte[] message,
HashAlgorithm hashAlg)
Message data in byte format
Hash algorithm to be used
String
Message digest in hex-encoded format
byte[] m = { 0x61, 0x62, 0x63 }; // "abc" in byte array
string s = Hash.HexFromBytes(m, HashAlgorithm.Sha256);
.WriteLine("SHA-256(b'abc')=\n" + s);
Console// ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
Hash Class
CryptoSysPKI Namespace
Create hash digest in hex format of a binary file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string HexFromFile(
string fileName,
HashAlgorithm hashAlg)
Name of file containing message data
Hash algorithm to be used
String
Message digest in hex-encoded format
Hash Class
CryptoSysPKI Namespace
Create hash digest in hex format of hex-encoded input.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string HexFromHex(
string messageHex,
HashAlgorithm hashAlg)
Message data in hex-encoded format
Hash algorithm to be used
String
Message digest in hex-encoded format
string m = "616263"; // "abc" encoded in a hex string
string s = Hash.HexFromHex(m, HashAlgorithm.Sha256);
.WriteLine("SHA-256('abc')=\n" + s);
Console// ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
Hash Class
CryptoSysPKI Namespace
Create hash digest in hex format of string input.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string HexFromString(
string message,
HashAlgorithm hashAlg)
Message data string
Hash algorithm to be used
String
Message digest in hex-encoded format
string m = "abc";
string s = Hash.HexFromString(m, HashAlgorithm.Sha256);
.WriteLine("SHA-256('abc')=\n" + s);
Console// ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
Hash Class
CryptoSysPKI Namespace
Create hash digest in hex format of a text file, treating CR-LF (0x13, 0x10) pairs as a single LF (0x10).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string HexFromTextFile(
string fileName,
HashAlgorithm hashAlg)
Name of file containing message data
Hash algorithm to be used
String
Message digest in hex format
This should give the same message digest of a text file on both Unix and Windows systems.
Hash Class
CryptoSysPKI Namespace
Return length of message digest output in bytes.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int Length(
HashAlgorithm hashAlg)
Hash algorithm
Int32
Length of the hash function output in bytes.
= HashAlgorithm.Sha256;
HashAlgorithm alg .WriteLine("len({0})={1}", alg.ToString(), Hash.Length(alg));
Console// len(Sha256)=32
Hash Class
CryptoSysPKI Namespace
Extension methods for hex conversion
System.Object
CryptoSysPKI.HexExtension
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static class HexExtension
The HexExtension type exposes the following members.
Name | Description |
---|---|
FromHex | Decode a hex-encoded string |
ToHex | Encode a byte array in hexadecimal |
Decode a hex-encoded string
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] FromHex(
this string s
)
Input string of hex characters
Byte[]
Decoded byte array #### Usage Note In Visual Basic and C#, you can call
this method as an instance method on any object of type String. When you
use instance method syntax to call this method, omit the first
parameter. For more information, see Extension
Methods (Visual Basic) or Extension
Methods (C# Programming Guide).
byte[] b = "00010203".FromHex();
// { 0x00, 0x01, 0x02, 0x03 };
HexExtension Class
CryptoSysPKI Namespace
Encode a byte array in hexadecimal
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string ToHex(
this byte[] b
)
Input byte array
String
Hex-encoded string #### Usage Note In Visual Basic and C#, you can call
this method as an instance method on any object of type Byte[]. When you
use instance method syntax to call this method, omit the first
parameter. For more information, see Extension
Methods (Visual Basic) or Extension
Methods (C# Programming Guide).
byte[] b = { 0x00, 0x01, 0x02, 0x03 };
string s = b.ToHex(); // 00010203
HexExtension Class
CryptoSysPKI Namespace
Keyed-hash based message authentication code (HMAC) functions
System.Object
CryptoSysPKI.Hmac
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Hmac
The Hmac type exposes the following members.
Name | Description |
---|---|
BytesFromBytes | Create a keyed-hash HMAC in byte format from byte input. |
HexFromBytes | Create a keyed-hash HMAC in hex-encoded format from byte input. |
HexFromHex | Create a keyed-hash HMAC in hex-encoded format from hex-encoded input. |
Create a keyed-hash HMAC in byte format from byte input.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] BytesFromBytes(
byte[] message,
byte[] key,
HashAlgorithm hashAlg)
Message to be signed in byte format
Key in byte format
Hash algorithm to be used
Byte[]
HMAC in byte format
.WriteLine("HMAC Test case 4 from RFC 2202 and RFC 4231...");
Console// Test case 4 from RFC 2202 and RFC 4231
// key = 0x0102030405060708090a0b0c0d0e0f10111213141516171819
// key_len 25
// data = 0xcd repeated 50 times
// data_len = 50
int i;
byte[] key = new byte[25];
for (i = 0; i < 25; i++)
[i] = (byte)(i + 1);
keybyte[] msg = new byte[50];
for (i = 0; i < 50; i++)
[i] = 0xcd;
msg// Compute HMAC-SHA-256
byte[] b = Hmac.BytesFromBytes(msg, key, HashAlgorithm.Sha256);
.WriteLine("HMAC-SHA-256(50(0xcd), 0x0102..19)=\n{0}", Cnv.ToHex(b));
Console// 82558A389A443C0EA4CC819899F2083A85F0FAA3E578F8077A2E3FF46729665B
Hmac Class
CryptoSysPKI Namespace
Create a keyed-hash HMAC in hex-encoded format from byte input.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string HexFromBytes(
byte[] message,
byte[] key,
HashAlgorithm hashAlg)
Message to be signed in byte format
Key in byte format
Hash algorithm to be used
String
HMAC in hex-encoded format
// Hmac of <Test Case 1> with input in hex format
string s = Hmac.HexFromHex("4869205468657265", "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", HashAlgorithm.Sha256);
.WriteLine("HMAC-SHA-256('Hi There', (0x0b)*20)=\n{0}", s);
Console// b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7
Hmac Class
CryptoSysPKI Namespace
Create a keyed-hash HMAC in hex-encoded format from hex-encoded input.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string HexFromHex(
string messageHex,
string keyHex,
HashAlgorithm hashAlg)
Message to be signed in hex-encoded format
Key in hex-encoded format
Hash algorithm to be used
String
HMAC in hex-encoded format
Hmac Class
CryptoSysPKI Namespace
Hybrid Public Key Encryption functions (HPKE)
System.Object
CryptoSysPKI.Hpke
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Hpke
The Hpke type exposes the following members.
Name | Description |
---|---|
DerivePrivateKey | Derive an EC private key in a deterministic manner from input keying material using the DeriveKeyPair algorithm in RFC9180. |
LabeledExpand | Compute the output of the LabeledExpand function as defined in RFC9180. |
LabeledExtract | Compute the output of the LabeledExtract function as defined in RFC9180. |
Derive an EC private key in a deterministic manner from input keying material using the DeriveKeyPair algorithm in RFC9180.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string DerivePrivateKey(
byte[] ikm,
.CurveName curveName,
Hpke.OutputOpts opts = Hpke.OutputOpts.Default
Hpke)
Input key material (ikm). This must have length in bytes at least as long as the key to be produced.
Curve name
Output options (default=internal key format)
String
Derived private key in string form or an empty string on error.
By default the key is output as an ephemeral “internal” key string,
which can be used directly with Ecc.SaveKey, Ecc.SaveEncKey, Ecc.PublicKeyFromPrivate, Ecc.DHSharedSecret and Ecc.QueryKey. If opts
is set
to OutputOpts.KeyAsHex
then the key is output in serialized
hexadecimal form in the same manner as the test vectors in [RFC9180]
(without the clamping). The KDF to be used is fixed by the EC curve
group as follows: | EC curve | KDF | | ——– | ———– | | P-256 |
HKDF-SHA256 | | P-384 | HKDF-SHA384 | | P-521 | HKDF-SHA512 | | X25519 |
HKDF-SHA256 | | X448 | HKDF-SHA512 |
string ikmhex = "7268600d403fce431561aef583ee1613527cff655c1343f29812e66706df3234";
string skhex = Hpke.DerivePrivateKey(Cnv.FromHex(ikmhex), Hpke.CurveName.X25519, Hpke.OutputOpts.KeyAsHex);
// 52c4a758a802cd8b936eceea314432798d5baf2d7e9235dc084ab1b9cfa2f736
Hpke Class
CryptoSysPKI Namespace
Compute the output of the LabeledExpand function as defined in RFC9180.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] LabeledExpand(
int numBytes,
byte[] prk,
string label,
byte[] info,
.CurveName curveName,
Hpke.AeadAlg aeadAlg = Hpke.AeadAlg.None
Hpke)
Required number of bytes (L) of output keying material.
Pseudorandom key (prk)
Label string
Byte string info
ECDH curve used in scheme
AEAD encryption algorithm used in the scheme or 0 (default) to indicate KDF is being used inside a KEM algorithm.
Byte[]
L bytes of output keying material.
The LabeledExpand
function is defined in section 4 of
[RFC9180]. It uses the “expand” stage of the HKDF function [RFC5869].
The ECDH curve group used in the scheme must be specified, which
automatically fixes the KDF and associated HMAC algorithm to be
used.
int Nk = 16;
// key = LabeledExpand(secret, 'key', key_schedule_context, Nk)
byte[] key = Hpke.LabeledExpand(Nk, Cnv.FromHex("12fff91991e93b48de37e7daddb52981084bd8aa64289c3788471d9a9712f397"), "key",
.FromHex("00725611c9d98c07c03f60095cd32d400d8347d45ed67097bbad50fc56da742d07cb6cffde367bb0565ba28bb02c90744a20f5ef37f30523526106f637abb05449"),
Cnv.CurveName.X25519, Hpke.AeadAlg.Aes_128_Gcm);
Hpke// 4531685d41d65f03dc48f6b8302c05b0
Hpke Class
CryptoSysPKI Namespace
Compute the output of the LabeledExtract function as defined in RFC9180.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] LabeledExtract(
byte[] salt,
string label,
byte[] ikm,
.CurveName curveName,
Hpke.AeadAlg aeadAlg = Hpke.AeadAlg.None
Hpke)
Byte string salt
Label string
Input keying material (ikm)
ECDH curve used in scheme
AEAD encryption algorithm used in the scheme or 0 (default) to indicate KDF is being used inside a KEM algorithm.
Byte[]
A pseudorandom key of fixed length Nh bytes.
The LabeledExtract
function is defined in section 4 of
[RFC9180]. It uses the “extract” stage of the HKDF function [RFC5869]
and outputs a fixed value of bytes equal to the length (Nh) of the
underlying HMAC function used by the KDF algorithm. The ECDH curve group
used in the scheme must be specified, which automatically fixes the KDF
and associated HMAC algorithm to be used.
// Used inside KEM
string ikmhex = "7268600d403fce431561aef583ee1613527cff655c1343f29812e66706df3234";
.WriteLine(Cnv.ToHex(Hpke.LabeledExtract(null, "dkp_prk", Cnv.FromHex(ikmhex), Hpke.CurveName.X25519)));
Console// 7B8BFE1D6F3D0CB45C585E133299C64AC998BF46CAF2DC13BA874F23413EC23A
// Used outside KEM
.WriteLine(Cnv.ToHex(Hpke.LabeledExtract(null, "psk_id_hash", null, Hpke.CurveName.X25519, Hpke.AeadAlg.Aes_128_Gcm)));
Console// 725611C9D98C07C03F60095CD32D400D8347D45ED67097BBAD50FC56DA742D07
Hpke Class
CryptoSysPKI Namespace
Key derivation functions (KDF)
System.Object
CryptoSysPKI.Kdf
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Kdf
The Kdf type exposes the following members.
Name | Description |
---|---|
Bytes | Generate a key-encryption key (KEK) from input keying material (IKM) using a key derivation function (KDF). |
ForCms | Generate a key-encryption key (KEK) for ECDH key exchange in a CMS EnvelopedData object. |
Generate a key-encryption key (KEK) from input keying material (IKM) using a key derivation function (KDF).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] Bytes(
int dkLen,
byte[] ikm,
.KdfAlg kdfAlg = Kdf.KdfAlg.X963,
Kdf.HashAlg hashAlg = Kdf.HashAlg.Sha1,
Kdfbyte[] sharedInfo = null,
string paramString = ""
)
Required length of output key material in bytes.
Input key material/shared secret.
Key derivation function to use.
Hash algorithm to use with the key derivation function (default is SHA-1)
SharedInfo (optional)
Optional parameters. Set as ""
for defaults. Pass
attribute-value salt=<hex-digits>
to set the optional
salt parameter for the HKDF algorithm,
e.g. "salt=606162636465666768696a6b6c6d6e6f;"
Byte[]
Output key material (KEK).
// [RFC 5869] A.1. Test Case 1 Basic test case with SHA-256
int nbytes = 42;
byte[] zz = "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b".FromHex();
byte [] info = "f0f1f2f3f4f5f6f7f8f9".FromHex();
byte[] kek = Kdf.Bytes(nbytes, zz, Kdf.KdfAlg.Hkdf, Kdf.HashAlg.Sha256, info, "salt=000102030405060708090a0b0c");
.WriteLine("KEK={0}", Cnv.ToHex(kek));
Console// KEK=3CB25F25FAACD57A90434F64D0362F2A2D2D0A90CF1A5A4C5DB02D56ECC4C5BF34007208D5B887185865
Kdf Class
CryptoSysPKI Namespace
Generate a key-encryption key (KEK) for ECDH key exchange in a CMS EnvelopedData object.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] ForCms(
byte[] zz,
.KeyWrapAlg keyWrapAlg,
Kdf.KdfAlg kdfAlg = Kdf.KdfAlg.X963,
Kdf.HashAlg hashAlg = Kdf.HashAlg.Sha1,
Kdfbyte[] ukm = null
)
Input key material/shared secret value (denoted variously as ZZ/Z/K/IKM)
Key wrap algorithm (required, cannot be Default)
Key derivation function to use.
Hash algorithm to use with the key derivation function (default is SHA-1)
Optional user key material (ukm)
Byte[]
Output key material (KEK).
This is a specialist function using the key definition algorithms described in [RFC5753] and [RFC8418] when used for key agreement with ECDH in a CMS EnvelopedData object. The key-encryption key is derived using the ECC-CMS-SharedInfo type, described in section 7.2 of [RFC5753].
Kdf Class
CryptoSysPKI Namespace
Online Certificate Status Protocol (OCSP)
System.Object
CryptoSysPKI.Ocsp
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Ocsp
The Ocsp type exposes the following members.
Name | Description |
---|---|
MakeRequest | Create an Online Certification Status Protocol (OCSP) request as a base64 string. |
ReadResponse | Read a response to an Online Certification Status Protocol (OCSP) request and outputs the main results in text form. |
Create an Online Certification Status Protocol (OCSP) request as a base64 string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string MakeRequest(
string issuerCert,
string certFileOrSerialNumber,
HashAlgorithm hashAlg)
name of issuer’s X.509 certificate file (or base64 representation)
either the name of X.509 certificate file to be checked or its serial number in hexadecimal format preceded by #x
Hash algorithm to be used [default = SHA-1]
String
A base64 string suitable for an OCSP request to an Online Certificate
Status Manager or an empty string on error.
The issuer’s X.509 certficate must be specified. The certificate to be checked can either be specified directly as a filename or as a serialNumber in hexadecimal format preceded by “#x”, e.g. “#x01deadbeef”. If the latter format is used, it must be in hexadecimal format, so the serial number 10 would be passed as “#x0a”. It is an error (NO_MATCH_ERROR) if the issuer’s name of the certificate to be checked does not match the subject name of the issuer’s certificate.
Ocsp Class
CryptoSysPKI Namespace
Read a response to an Online Certification Status Protocol (OCSP) request and outputs the main results in text form.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string ReadResponse(
string responseFile,
string issuerCert
)
name of the file containing the response data in BER format.
(optional) name of issuer’s X.509 certificate file (or base64 representation)
String
A text string outlining the main results in the response data or an
empty string on error.
Note that a revoked certificate will still result in a “Successful
response”, so check the CertStatus. The issuer’s X.509 certficate
issuerCert
is optional. If provided, it will be used to
check the signature on the OCSP reponse and and an error will result if
the signature is not valid. CAUTION: For some CAs
(e.g. VeriSign) the key used to sign the OCSP response is not the same
as the key in the issuer’s certificate, so specifying the issuer’s
certificate in this case will result in a signature error. If you can
separately obtain the certificate used to sign the OCSP response, then
specify this as the issuerCert
; otherwise leave as the
empty string ""
.
Ocsp Class
CryptoSysPKI Namespace
Password-based encryption
System.Object
CryptoSysPKI.Pbe
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Pbe
The Pbe type exposes the following members.
Name | Description |
---|---|
Kdf2(Int32, Byte[], Byte[], Int32, HashAlgorithm) | Derive a key of any length from a password using the PBKDF2 algorithm from PKCS #5 v2.1. |
Kdf2(Int32, String, String, Int32, HashAlgorithm) | Derive a key in hex format of any length from a password with the salt in hex format. |
Scrypt(Int32, Byte[], Byte[], Int32, Int32, Int32) | Derives a key of any length from a password using the SCRYPT algorithm. |
Scrypt(Int32, String, String, Int32, Int32, Int32) | Derives a key in hex format from a password with the salt in hex format |
Derive a key of any length from a password using the PBKDF2 algorithm from PKCS #5 v2.1.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Kdf2(Int32, Byte[], Byte[], Int32, HashAlgorithm) | Derive a key of any length from a password using the PBKDF2 algorithm from PKCS #5 v2.1. |
Kdf2(Int32, String, String, Int32, HashAlgorithm) | Derive a key in hex format of any length from a password with the salt in hex format. |
public static byte[] Kdf2(
int dkLen,
byte[] pwdBytes,
byte[] salt,
int count,
= HashAlgorithm.Sha1
HashAlgorithm hashAlg )
Required length of key in bytes
Password in byte format
Salt in byte format
Iteration count
Hash algorithm to use in HMAC PRF (default is SHA-1)
Byte[]
Key in byte[] format
// Use PBKDF2 with SHA-256 hash function to derive 192-bit key
// convert password string to bytes
byte[] pwd = System.Text.Encoding.Default.GetBytes("password");
// make a salt
byte[] salt = new byte[] { 0x78, 0x57, 0x8e, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
int n = 24;
byte[] key = Pbe.Kdf2(n, pwd, salt, 2048, HashAlgorithm.Sha256);
.WriteLine("Key({0})={1}", n * 8, key.ToHex());
Console// Key(192)=97B5A91D35AF542324881315C4F849E327C4707D1BC9D322
Pbe Class
CryptoSysPKI Namespace
Derive a key in hex format of any length from a password with the salt in hex format.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Kdf2(Int32, Byte[], Byte[], Int32, HashAlgorithm) | Derive a key of any length from a password using the PBKDF2 algorithm from PKCS #5 v2.1. |
Kdf2(Int32, String, String, Int32, HashAlgorithm) | Derive a key in hex format of any length from a password with the salt in hex format. |
public static string Kdf2(
int dkLen,
string pwdStr,
string saltHex,
int count,
= HashAlgorithm.Sha1
HashAlgorithm hashAlg )
Required length of key in bytes
Password
Salt in hex format
Iteration count
Hash algorithm to use in HMAC PRF (default is SHA-1)
String
Key in hex format
string saltHex = "78578e5a5d63cb06";
int n = 24;
string keyStr = Pbe.Kdf2(n, "password", saltHex, 2048, HashAlgorithm.Sha256);
.Assert(keyStr.Length > 0, "ERROR with PbeKdf2/Hex");
Debug.WriteLine("Key({0})={1}", n * 8, keyStr);
Console// Key(192)=97B5A91D35AF542324881315C4F849E327C4707D1BC9D322
Pbe Class
CryptoSysPKI Namespace
Derives a key of any length from a password using the SCRYPT algorithm.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Scrypt(Int32, Byte[], Byte[], Int32, Int32, Int32) | Derives a key of any length from a password using the SCRYPT algorithm. |
Scrypt(Int32, String, String, Int32, Int32, Int32) | Derives a key in hex format from a password with the salt in hex format |
public static byte[] Scrypt(
int dkLen,
byte[] pwdBytes,
byte[] salt,
int N,
int r,
int p
)
Required length of key in bytes
Password encoded in byte format
Salt in byte format
CPU/Memory cost parameter, a number greater than one and a power of 2.
Block size r
Parallelization parameter p
Byte[]
Key in byte[] format
// Test vectors from [RFC7914]
// scrypt (P="password", S="NaCl", N=1024, r=8, p=16, dkLen=64)
int dkLen = 64;
byte[] pwd = System.Text.Encoding.Default.GetBytes("password");
byte[] salt = System.Text.Encoding.Default.GetBytes("NaCl");
byte[] key = Pbe.Scrypt(dkLen, pwd, salt, 1024, 8, 16);
.Assert(key.Length > 0, "ERROR with Pbe.Scrypt");
Debug.WriteLine("dk={0}", key.ToHex());
Console// FDBABE1C9D3472007856E7190D01E9FE7C6AD7CBC8237830E77376634B373162
// 2EAF30D92E22A3886FF109279D9830DAC727AFB94A83EE6D8360CBDFA2CC0640
Pbe Class
CryptoSysPKI Namespace
Derives a key in hex format from a password with the salt in hex format
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Scrypt(Int32, Byte[], Byte[], Int32, Int32, Int32) | Derives a key of any length from a password using the SCRYPT algorithm. |
Scrypt(Int32, String, String, Int32, Int32, Int32) | Derives a key in hex format from a password with the salt in hex format |
public static string Scrypt(
int dkLen,
string pwdStr,
string saltHex,
int N,
int r,
int p
)
Required length of key in bytes
Password (normal text)
Salt in hex format
CPU/Memory cost parameter, a number greater than one and a power of 2.
Block size r
Parallelization parameter p
String
Key in hex format
Password pwdStr
is normal text, not hexadecimal
string keyHex = Pbe.Scrypt(64, "password", "4E61436C", 1024, 8, 16);
Pbe Class
CryptoSysPKI Namespace
PEM file conversion routines
System.Object
CryptoSysPKI.Pem
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Pem
The Pem type exposes the following members.
Name | Description |
---|---|
FileFromBinFile | Create a PEM file from a binary file with option for line endings. |
FileToBinFile | Convert the contents of a PEM file into a binary file. |
Create a PEM file from a binary file with option for line endings.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int FileFromBinFile(
string fileToMake,
string fileIn,
string header,
int lineLen,
bool unixEOL = false
)
Name of PEM file to create
Name of input binary file
Header to be used. Leave empty to omit the PEM header and footer.
Maximum length of a line in the resulting PEM file [default = 64 characters]
Set true for Unix/SSL LF line endings [optional, default = Windows CR-LF endings]
Int32
Zero if successful; otherwise it returns an error code
Pem Class
CryptoSysPKI Namespace
Convert the contents of a PEM file into a binary file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int FileToBinFile(
string fileToMake,
string fileIn
)
Name of binary file to create.
Name of input PEM file
Int32
Zero if successful; otherwise it returns an error code
Pem Class
CryptoSysPKI Namespace
PKCS-12 (PFX) File Functions
System.Object
CryptoSysPKI.Pfx
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Pfx
The Pfx type exposes the following members.
Name | Description |
---|---|
MakeFile | Create a PFX (PKCS-12) file from an X.509 certificate and (optional) encrypted private key file with advanced options. |
SignatureIsValid | Verify the MacData signature in a PKCS-12 file. |
Create a PFX (PKCS-12) file from an X.509 certificate and (optional) encrypted private key file with advanced options.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int MakeFile(
string fileToMake,
string certFile,
string privateKeyFile,
string password,
string friendlyName,
.Options pfxOptions
Pfx)
name of output file to be created
filename of the subject’s X.509 certificate (required)
filename of the subject’s encrypted private key in pkcs-8 format (optional)
password for private key file and new PFX file
friendly name identification for the subject (optional)
Specialist options
Int32
Zero if successful or a non-zero error
code.
The default behaviour is to encrypt the certificate using “weak”
40-bit RC2 and the private key (if provided) using “standard” Triple DES
(pbeWithSHAAnd3-KeyTripleDES-CBC
).
Pfx Class
CryptoSysPKI Namespace
Verify the MacData signature in a PKCS-12 file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static bool SignatureIsValid(
string fileName,
string password
)
Name of PKCS-12 file to be checked
password for file
Boolean
true
if signature is OK
Pfx Class
CryptoSysPKI Namespace
Pseudorandom function (PRF) methods.
System.Object
CryptoSysPKI.Prf
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Prf
The Prf type exposes the following members.
Name | Description |
---|---|
Bytes | Generate output bytes using a pseudorandom function (PRF). |
Generate output bytes using a pseudorandom function (PRF).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] Bytes(
int numBytes,
byte[] message,
byte[] key,
.Alg prfAlg,
Prfstring customStr = ""
)
Required number of output bytes.
Input message data.
Key.
PRF algorithm.
Customization string (optional).
Byte[]
Output data in byte array.
// Sample #1: "standard" KMAC output length KMAC128 => 256 bits, no custom string
int nbytes = 256 / 8;
byte[] msg = "00010203".FromHex();
byte[] key = "404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F".FromHex();
byte[] b = Prf.Bytes(nbytes, msg, key, Prf.Alg.Kmac128);
.WriteLine("OUT={0}", b.ToHex());
Console// E5780B0D3EA6F7D3A429C5706AA43A00FADBD7D49628839E3187243F456EE14E
Prf Class
CryptoSysPKI Namespace
Password Dialog Functions
System.Object
CryptoSysPKI.Pwd
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Pwd
The Pwd type exposes the following members.
Name | Description |
---|---|
Prompt | Open a dialog box to receive a password with user-supplied prompt. |
Open a dialog box to receive a password with user-supplied prompt.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string Prompt(
int maxChars,
string caption,
string prompt = ""
)
Maximum characters expected in password
Caption for dialog window
Wording for prompt (optional, default=“Enter password:”)
String
String containing password or Empty string if user cancels
string s = Pwd.Prompt(32, "My caption for the dialog here", "My new prompt:");
.WriteLine("Password=[{0}]", s); // Demo only! Console
Pwd Class
CryptoSysPKI Namespace
Random Number Generator to NIST SP800-90
System.Object
CryptoSysPKI.Rng
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Rng
The Rng type exposes the following members.
Name | Description |
---|---|
Bytes(Int32) | Generate an array of random bytes. |
Bytes(Int32, Byte[]) | Generate an array of random bytes with user-supplied entropy. |
Bytes(Int32, String) | Generate an array of random bytes with user-supplied entropy. |
BytesWithPrompt(Int32, Rng.Strength) | Generate an array of random bytes with a prompt for random keyboard input. |
BytesWithPrompt(Int32, String, Rng.Strength) | Generate an array of random bytes with a prompt for random keyboard input. |
Guid | Generate a random 36-character Global Unique IDentifier (GUID) string according to [RFC4122]. |
Initialize | Initialize the RNG generator with a seed file. |
InitializeEx | Query and initialize the RNG generator using Intel(R) DRNG, if available. |
MakeSeedFile | Create a new seed file suitable for use with Rng.Initialize. |
Number | Generate a random number (integer) in a given range. |
Octet | Generate a single random octet (byte). |
Test | Carry out a NIST SP800-90 health check and FIPS140-2 statistical tests on the random number generator. |
TestDrbgvs | Test the RNG for conformance to NIST SP800-90A using the relevant test specified in DRBGVS. |
UpdateSeedFile | Update the RNG seed file. |
Name | Description |
---|---|
SeedFileSize | Required size for RNG seed file |
Generate an array of random bytes.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Bytes(Int32) | Generate an array of random bytes. |
Bytes(Int32, Byte[]) | Generate an array of random bytes with user-supplied entropy. |
Bytes(Int32, String) | Generate an array of random bytes with user-supplied entropy. |
public static byte[] Bytes(
int numBytes
)
Required number of random bytes
Byte[]
Array of random bytes
byte[] b = Rng.Bytes(16);
.WriteLine("Rng.Bytes(16)={0}", b.ToHex());
Console// e.g. 3FD45EB7715CE91C9F1DB69DBF6677ED (always different)
Rng Class
CryptoSysPKI Namespace
Generate an array of random bytes with user-supplied entropy.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Bytes(Int32) | Generate an array of random bytes. |
Bytes(Int32, Byte[]) | Generate an array of random bytes with user-supplied entropy. |
Bytes(Int32, String) | Generate an array of random bytes with user-supplied entropy. |
public static byte[] Bytes(
int numBytes,
byte[] arrSeed
)
Required number of random bytes
User-supplied entropy in byte format
Byte[]
Array of random bytes
Rng Class
CryptoSysPKI Namespace
Generate an array of random bytes with user-supplied entropy.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Bytes(Int32) | Generate an array of random bytes. |
Bytes(Int32, Byte[]) | Generate an array of random bytes with user-supplied entropy. |
Bytes(Int32, String) | Generate an array of random bytes with user-supplied entropy. |
public static byte[] Bytes(
int numBytes,
string seedStr
)
Required number of random bytes
User-supplied entropy in string format
Byte[]
Array of random bytes
Rng Class
CryptoSysPKI Namespace
Generate an array of random bytes with a prompt for random keyboard input.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
BytesWithPrompt(Int32, Rng.Strength) | Generate an array of random bytes with a prompt for random keyboard input. |
BytesWithPrompt(Int32, String, Rng.Strength) | Generate an array of random bytes with a prompt for random keyboard input. |
public static byte[] BytesWithPrompt(
int numBytes,
.Strength strength = Rng.Strength.Default
Rng)
Required number of random bytes
Estimated security strength (default=112 bits)
Byte[]
Array of random bytes
Rng Class
CryptoSysPKI Namespace
Generate an array of random bytes with a prompt for random keyboard input.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
BytesWithPrompt(Int32, Rng.Strength) | Generate an array of random bytes with a prompt for random keyboard input. |
BytesWithPrompt(Int32, String, Rng.Strength) | Generate an array of random bytes with a prompt for random keyboard input. |
public static byte[] BytesWithPrompt(
int numBytes,
string prompt,
.Strength strength
Rng)
Required number of random bytes
Alternative prompt. Set as an empty string ""
for the
default prompt.
Required security strength
Byte[]
Array of random bytes
Rng Class
CryptoSysPKI Namespace
Generate a random 36-character Global Unique IDentifier (GUID) string according to [RFC4122].
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string Guid()
String
String of the form “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx” where ‘x’ is a
hexadecimal digit [0-9a-f]
.
string guid = Rng.Guid();
.WriteLine("GUID={0}", guid);
Console// Example: GUID=14e3d83a-2de2-4fb0-851c-840fbab04cdd
Rng Class
CryptoSysPKI Namespace
Initialize the RNG generator with a seed file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static bool Initialize(
string seedFile
)
Full path name of seed file
Boolean
true
if successful; false
if fails
If the seed file does not exist, it will be created (with any available entropy).
Rng Class
CryptoSysPKI Namespace
Query and initialize the RNG generator using Intel(R) DRNG, if available.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int InitializeEx(
.Options opts = Rng.Options.Default
Rng)
Specify Rng.Options.NoIntelDrng
to explicitly turn off
support.
Int32
Support status for Intel(R) DRNG. If available, then a positive value
(1,2,3); else a negative error code.
Rng Class
CryptoSysPKI Namespace
Create a new seed file suitable for use with Rng.Initialize.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static bool MakeSeedFile(
string seedFile,
.Strength strength = Rng.Strength.Default
Rng)
Name of seed file to be created
Estimated security strength (default=112 bits)
Boolean
true
if successful; false
if fails
Any existing file will be overwritten.
Rng Class
CryptoSysPKI Namespace
Generate a random number (integer) in a given range.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int Number(
int lower,
int upper
)
lower value of range
upper value of range
Int32
Random integer x: lower <= x <= upper
int i;
for (i = 0; i < 12; i++) {
int n = Rng.Number(-10, +10);
.Write("{0} ", n);
Console}
.Write("\n"); Console
Rng Class
CryptoSysPKI Namespace
Generate a single random octet (byte).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte Octet()
Byte
Single byte value randomly chosen between 0 and 255
byte by = Rng.Octet(); // Generate a random single byte (octet)
.WriteLine("Rng.Octet()={0}", by); // 0 <= by < 256 Console
Rng Class
CryptoSysPKI Namespace
Carry out a NIST SP800-90 health check and FIPS140-2 statistical tests on the random number generator.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static bool Test(
string resultFile = ""
)
Name of results file to be created, or null
not to
create a results file.
Boolean
true
if successful; false
if fails
Any existing file will be overwritten.
Rng Class
CryptoSysPKI Namespace
Test the RNG for conformance to NIST SP800-90A using the relevant test specified in DRBGVS.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string TestDrbgvs(
int returnedBitsLen,
string entropyInput,
string nonce,
string personalizationString,
string additionalInput1,
string entropyReseed,
string additionalInputReseed,
string additionalInput2
)
Number of bits to be returned from each call to the generate function in the test
the EntropyInput value in hex format
the Nonce value in hex format
the PersonalizationString value in hex format
the first AdditionalInput value in hex format
the EntropyReseed value in hex format
the AdditionalInputReseed value in hex format
the second AdditionalInput value in hex format
String
the ReturnedBits as a string in hexadecimal format
The test procedure, the input values and the expected output are
described in the DRBGVS document. The relevant DRBG mechanism is
HMAC_DRBG SHA-512
without prediction resistance. Use the
empty string ""
to pass a zero-length input. All hex
strings must have an even number of characters.
Rng Class
CryptoSysPKI Namespace
Update the RNG seed file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static bool UpdateSeedFile(
string seedFile
)
Full path name of seed file
Boolean
true
if successful; false
if fails
The seed file must be writable. If it does not exist it will be created (with any available entropy). Any existing file of the same name will be overwritten without warning.
Rng Class
CryptoSysPKI Namespace
Required size for RNG seed file
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public const int SeedFileSize = 128
Int32
Rng Class
CryptoSysPKI Namespace
RSA Encryption and Public Key Functions
System.Object
CryptoSysPKI.Rsa
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Rsa
The Rsa type exposes the following members.
Name | Description |
---|---|
CheckKey(String) | Check the validity of an “internal” RSA public or private key. |
CheckKey(StringBuilder) | Check the validity of an “internal” RSA public or private key. |
DecodeDigestForSignature | Decode an encoded message for signature. |
DecodeMsgForEncryption | Decode a message for encryption. |
DecodeMsgIso9796 | Decode a message padded using ISO/IEC 9796-1 formatting. |
Decrypt | Decrypt a message encrypted using an RSA encryption scheme. |
EncodeDigestForSignature | Encode a message digest for signature. |
EncodeMsgForEncryption | Encode a message for encryption. |
EncodeMsgForSignature | Encode a message for signature. |
EncodeMsgIso9796 | Encode a message using ISO/IEC 9796-1 formatting. |
Encrypt | Encrypt a short message using RSA encryption. |
FromXMLString(String) | Create an RSA key string in internal format from an XML string. |
FromXMLString(String, Rsa.XmlOptions) | Create an RSA key string in internal format from an XML string with options. |
FromXMLString(String, Boolean) | Create an RSA key string in internal format from an XML string with flag to exclude private key details. |
GetPrivateKeyFromPFX | Extract an encrypted private key from a PKCS-12 PKCS8ShroudedKeyBag, saving the output directly as a new file. |
GetPublicKeyFromCert | Obsolete. Read public key from X.509 certificate into internal string format. |
KeyBits(String) | Return number of significant bits in RSA key modulus. |
KeyBits(StringBuilder) | Return number of significant bits in RSA key modulus. |
KeyBytes(String) | Return number of bytes (octets) in RSA key modulus. |
KeyBytes(StringBuilder) | Return number of bytes (octets) in RSA key modulus. |
KeyHashCode(String) | Compute the hash code of an “internal” RSA public or private key string. |
KeyHashCode(StringBuilder) | Compute the hash code of an “internal” RSA public or private key string. |
KeyMatch(String, String) | Verify that a pair of “internal” RSA private and public key strings are matched. |
KeyMatch(StringBuilder, StringBuilder) | Verify that a pair of “internal” RSA private and public key strings are matched. |
KeyValue | Extract a base64-encoded RSA key value from internal key string |
MakeKeys(String, String, Int32, Rsa.PublicExponent, Int32, String, Rsa.PbeOptions, Boolean, Byte[]) | Obsolete. Generate an RSA public/private key pair [DEPRECATED]. |
MakeKeys(String, String, String, Int32, Rsa.PublicExponent, Rsa.PbeOptions, String, Rsa.Format, Boolean) | Generate an RSA public/private key pair. |
MakeKeys(String, String, Int32, Rsa.PublicExponent, Int32, String, CipherAlgorithm, HashAlgorithm, Rsa.Format, Boolean) | Obsolete. Generate an RSA public/private key pair with extended options for encrypting private key [DEPRECATED]. |
PublicKeyFromPrivate | Convert an internal private key string into a public one. |
RawPrivate(Byte[], String) | Carry out RSA transformation using private key. |
RawPrivate(Byte[], String, Int32) | Carry out RSA transformation using private key (with specialist options). |
RawPublic(Byte[], String) | Carry out RSA transformation using public key. |
RawPublic(Byte[], String, Int32) | Carry out RSA transformation using public key (with specialist options). |
ReadEncPrivateKey | Obsolete. Read encrypted private key file into internal string format. |
ReadPrivateKey | Read from a file or string containing a private key into an “internal” private key string. |
ReadPrivateKeyFromPFX | Obsolete. Read a private key directly from an encrypted PFX/PKCS-12 file into an “internal” private key string. |
ReadPrivateKeyInfo | Obsolete. Read from an (unencrypted) PKCS-8 private key info file into a private key string. |
ReadPublicKey | Read from a file or string containing a public key into an “internal” public key string. |
SaveEncKey | Save an internal RSA key string to an encrypted key file. |
SaveEncPrivateKey(String, String, Int32, String, Rsa.PbeOptions, Rsa.Format) | Save a private key string to a PKCS-8 EncryptedPrivateKeyInfo file [DEPRECATED]. |
SaveEncPrivateKey(String, String, Int32, String, CipherAlgorithm, HashAlgorithm, Rsa.Format) | Save a private key string to a PKCS-8 EncryptedPrivateKeyInfo file using PBES2 algorithm [DEPRECATED]. |
SavePrivateKeyInfo | Save a private key string to an (unencrypted) PKCS-8 private key info file. |
SavePublicKey | Save a public key string to PKCS-1 public key file. |
ToXMLString(String, Rsa.XmlOptions) | Create an XML string representation of an RSA internal key string. |
ToXMLString(String, String, Rsa.XmlOptions) | Create an XML string representation of an RSA internal key string with option to add a namespace prefix. |
Check the validity of an “internal” RSA public or private key.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
CheckKey(String) | Check the validity of an “internal” RSA public or private key. |
CheckKey(StringBuilder) | Check the validity of an “internal” RSA public or private key. |
public static int CheckKey(
string intKeyString
)
Internal key string
Int32
0=valid private key, 1=valid publickey, or negative error code
A private key is also validated for consistency.
Rsa Class
CryptoSysPKI Namespace
Check the validity of an “internal” RSA public or private key.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
CheckKey(String) | Check the validity of an “internal” RSA public or private key. |
CheckKey(StringBuilder) | Check the validity of an “internal” RSA public or private key. |
public static int CheckKey(
StringBuilder sbKeyString)
Internal key string
Int32
0=valid private key, 1=valid publickey, or negative error code
A private key is also validated for consistency.
Rsa Class
CryptoSysPKI Namespace
Decode an encoded message for signature.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] DecodeDigestForSignature(
byte[] data,
bool getFullDigestInfo = false
)
Encoded message for signature
(optional) If true, extract the full DigestInfo
;
otherwise just extract the message digest itself
Byte[]
Decoded data or an empty array on error
Only EMSA-PKCS1-v1_5 is supported in this function.
Rsa Class
CryptoSysPKI Namespace
Decode a message for encryption.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] DecodeMsgForEncryption(
byte[] data,
.EME method
Rsa)
Encoded message
Encoding method used
Byte[]
Decoded message
Rsa Class
CryptoSysPKI Namespace
Decode a message padded using ISO/IEC 9796-1 formatting.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] DecodeMsgIso9796(
byte[] data,
int keyBits
)
encoded message for signature
exact length of key in bits
Byte[]
Recovered message or an empty array on error
Rsa Class
CryptoSysPKI Namespace
EncodeMsgIso9796(Byte[], Int32)
Decrypt a message encrypted using an RSA encryption scheme.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] Decrypt(
byte[] data,
string privateKeyFile,
string password = "",
.EME method = Rsa.EME.PKCSv1_5,
Rsa.HashAlg hashAlg = Rsa.HashAlg.Sha1,
Rsa.AdvOptions advOpts = Rsa.AdvOptions.Default
Rsa)
Data to be decrypted (must be exactly the same length as the key modulus size).
Name of the private key file, or a string containing the key in PEM format, or a valid internal private key string.
Password for encrypted private key, or ""
if password is
not required.
Encoding method [optional, default = EME.PKCSv1_5]
Hash function for EME-OAEP encoding, otherwise ignored.
Advanced options for EME-OEAP only.
Byte[]
Decrypted data.
For RSA-OAEP you must set the correct options to match the parameters used for the encryption.
Rsa Class
CryptoSysPKI Namespace
Encode a message digest for signature.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] EncodeDigestForSignature(
int keyBytes,
byte[] digest,
HashAlgorithm hashAlg)
Number of bytes in the key
Digest of message
Message digest algorithm used to create digest
Byte[]
Encoded block
Only EMSA-PKCS1-v1_5 is supported in this function.
Rsa Class
CryptoSysPKI Namespace
SignData(Byte[],
String, String, SigAlgorithm, Sig.SigOptions, Sig.Encoding)
Compute a signature value over data in a byte array.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string SignData(
byte[] data,
string privateKeyFile,
string password,
,
SigAlgorithm sigAlg.SigOptions sigOpts = Sig.SigOptions.Default,
Sig.Encoding sigEncoding = Sig.Encoding.Default
Sig)
input data to be signed
Name of private key file (or a string containing the key in PEM format, or an internal private key)
Password for the private key, if encrypted
Signature algorithm to be used
(optional) Options for ECDSA and RSA-PSS signatures
Optional encodings for output [default=base64]
String
The encoded signature, or an empty string on error
string keyFile = "AlicePrivRSASign.p8e"; // Used to sign data
string password = "password";
// Input to be signed: a byte array with ASCII string "abc"
byte[] b = System.Text.Encoding.Default.GetBytes("abc");
string sig = Sig.SignData(b, keyFile, password, SigAlgorithm.Default);
.WriteLine("Sig.SignData returns \n'" + sig + "'");
Console/*
YK1aePtKQDDsVCyJdM0V9VOE6DZVTO3ZoyLV9BNcYmep0glwxU5mUQcLAUTUOETImTIN2
Pp4GffrxqdxUoczLshnXBNhg7P4ofge+WlBgmcTCnVv27LHHZpmdEbjTg6tnPMb+2b4Fv
MZ0LfkMKXyiRVTmG4ANyAmHH6QIsDZ8R8=*/
Sig Class
CryptoSysPKI Namespace
Encode a message for encryption.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] EncodeMsgForEncryption(
int keyBytes,
byte[] message,
.EME method
Rsa)
Number of bytes in the key
Message to be encoded
Encoding method to use
Byte[]
Encoded message block
Rsa Class
CryptoSysPKI Namespace
Encode a message for signature.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] EncodeMsgForSignature(
int keyBytes,
byte[] message,
HashAlgorithm hashAlg)
Number of bytes in the key
Message to be encoded
Message digest algorithm to use
Byte[]
Encoded block
Only EMSA-PKCS1-v1_5 is supported in this function. Note we can only ever recover the digest from the encoded block.
Rsa Class
CryptoSysPKI Namespace
SignData(Byte[],
String, String, SigAlgorithm, Sig.SigOptions, Sig.Encoding)
Encode a message using ISO/IEC 9796-1 formatting.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] EncodeMsgIso9796(
byte[] message,
int keyBits
)
message to be encoded
exact length of key in bits
Byte[]
Padded message block ready for signing or an empty array on error
The output block will be the same size as the key rounded up to the next whole byte. The message must be no longer than half the key length.
Rsa Class
CryptoSysPKI Namespace
DecodeMsgIso9796(Byte[], Int32)
Encrypt a short message using RSA encryption.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] Encrypt(
byte[] data,
string publicKeyFile,
.EME method = Rsa.EME.PKCSv1_5,
Rsa.HashAlg hashAlg = Rsa.HashAlg.Sha1,
Rsa.AdvOptions advOpts = Rsa.AdvOptions.Default
Rsa)
Data to be encrypted
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.
Encoding method [optional, default = EME.PKCSv1_5]
Hash function for EME-OAEP encoding, otherwise ignored.
Advanced options for EME-OEAP only.
Byte[]
Encrypted data or an empty array on error.
Rsa Class
CryptoSysPKI Namespace
Create an RSA key string in internal format from an XML string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
FromXMLString(String) | Create an RSA key string in internal format from an XML string. |
FromXMLString(String, Rsa.XmlOptions) | Create an RSA key string in internal format from an XML string with options. |
FromXMLString(String, Boolean) | Create an RSA key string in internal format from an XML string with flag to exclude private key details. |
public static string FromXMLString(
string xmlString
)
The XML string to use to reconstruct the RSA key
String
Key string in internal format or empty string on error
Creates an internal private key string if the XML contains private key parameters, otherwise an internal public key string.
Rsa Class
CryptoSysPKI Namespace
Create an RSA key string in internal format from an XML string with options.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
FromXMLString(String) | Create an RSA key string in internal format from an XML string. |
FromXMLString(String, Rsa.XmlOptions) | Create an RSA key string in internal format from an XML string with options. |
FromXMLString(String, Boolean) | Create an RSA key string in internal format from an XML string with flag to exclude private key details. |
public static string FromXMLString(
string xmlString,
.XmlOptions options
Rsa)
The XML string to use to reconstruct the RSA key
Option flags: set as zero for defaults.
String
Key string in internal format or empty string on error
Rsa Class
CryptoSysPKI Namespace
Create an RSA key string in internal format from an XML string with flag to exclude private key details.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
FromXMLString(String) | Create an RSA key string in internal format from an XML string. |
FromXMLString(String, Rsa.XmlOptions) | Create an RSA key string in internal format from an XML string with options. |
FromXMLString(String, Boolean) | Create an RSA key string in internal format from an XML string with flag to exclude private key details. |
public static string FromXMLString(
string xmlString,
bool excludePrivateParams
)
The XML string to use to reconstruct the RSA key
Reconstruct public key details only
String
Key string in internal format or empty string on error
Rsa Class
CryptoSysPKI Namespace
Extract an encrypted private key from a PKCS-12 PKCS8ShroudedKeyBag, saving the output directly as a new file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int GetPrivateKeyFromPFX(
string outputFile,
string pfxFile
)
Name of new file to create
PKCS-12 filename
Int32
If successful, it returns the number of bytes written to the output
file; otherwise it returns a negative error code
Rsa Class
CryptoSysPKI Namespace
Note: This API is now obsolete. Read public key from X.509 certificate into internal string format.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[ObsoleteAttribute("Use Rsa.ReadPublicKey() instead", false)]
public static StringBuilder GetPublicKeyFromCert(
string certFile
)
Filename of certificate file (or its base64 representation)
StringBuilder
StringBuilder containing an internal representation of the public key;
or an empty StringBuilder if error
This returns a StringBuilder, not a string. Use sb.ToString() to obtain a string.
Rsa Class
CryptoSysPKI Namespace
Return number of significant bits in RSA key modulus.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
KeyBits(String) | Return number of significant bits in RSA key modulus. |
KeyBits(StringBuilder) | Return number of significant bits in RSA key modulus. |
public static int KeyBits(
string strRsaKey
)
Internal key string
Int32
Number of significant bits in key
Rsa Class
CryptoSysPKI Namespace
Return number of significant bits in RSA key modulus.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
KeyBits(String) | Return number of significant bits in RSA key modulus. |
KeyBits(StringBuilder) | Return number of significant bits in RSA key modulus. |
public static int KeyBits(
StringBuilder sbRsaKey)
Internal key string
Int32
Number of significant bits in key
Rsa Class
CryptoSysPKI Namespace
Return number of bytes (octets) in RSA key modulus.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
KeyBytes(String) | Return number of bytes (octets) in RSA key modulus. |
KeyBytes(StringBuilder) | Return number of bytes (octets) in RSA key modulus. |
public static int KeyBytes(
string strRsaKey
)
Internal key string
Int32
Number of bytes in key
Rsa Class
CryptoSysPKI Namespace
Return number of bytes (octets) in RSA key modulus.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
KeyBytes(String) | Return number of bytes (octets) in RSA key modulus. |
KeyBytes(StringBuilder) | Return number of bytes (octets) in RSA key modulus. |
public static int KeyBytes(
StringBuilder sbRsaKey)
Internal key string
Int32
Number of bytes in key
Rsa Class
CryptoSysPKI Namespace
Compute the hash code of an “internal” RSA public or private key string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
KeyHashCode(String) | Compute the hash code of an “internal” RSA public or private key string. |
KeyHashCode(StringBuilder) | Compute the hash code of an “internal” RSA public or private key string. |
public static int KeyHashCode(
string intKeyString
)
Internal key string
Int32
A 32-bit hash code for the key, or zero on error.
Should be the same for a matching private and public key.
Rsa Class
CryptoSysPKI Namespace
Compute the hash code of an “internal” RSA public or private key string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
KeyHashCode(String) | Compute the hash code of an “internal” RSA public or private key string. |
KeyHashCode(StringBuilder) | Compute the hash code of an “internal” RSA public or private key string. |
public static int KeyHashCode(
StringBuilder sbKeyString)
Internal key string
Int32
A 32-bit hash code for the key, or zero on error.
// Use Rsa.KeyHashCode for matching public and private keys
= Rsa.ReadPrivateKey("lamps-alice.p8", ""); // Unencrypted .p8 file
StringBuilder sbPrivateKey = Rsa.ReadPublicKey("lamps-alice.cer"); // Matching X.509 certificate
StringBuilder sbPublicKey .WriteLine("Private Key: Rsa.KeyHashCode={0,8:X}", Rsa.KeyHashCode(sbPrivateKey.ToString()));
Console.WriteLine("Public Key: Rsa.KeyHashCode={0,8:X}", Rsa.KeyHashCode(sbPublicKey.ToString()));
Console// Private Key: Rsa.KeyHashCode=CA0B84DA
// Public Key: Rsa.KeyHashCode=CA0B84DA
Rsa Class
CryptoSysPKI Namespace
Verify that a pair of “internal” RSA private and public key strings are matched.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
KeyMatch(String, String) | Verify that a pair of “internal” RSA private and public key strings are matched. |
KeyMatch(StringBuilder, StringBuilder) | Verify that a pair of “internal” RSA private and public key strings are matched. |
public static int KeyMatch(
string privateKey,
string publicKey
)
Internal RSA private key string
Internal RSA public key string
Int32
0=valid key pair, or negative error
code
= Rsa.ReadPublicKey(pubkeyFile);
StringBuilder sbPublicKey = Rsa.ReadPrivateKey(prikeyFile, "password");
StringBuilder sbPrivateKey int n = Rsa.KeyMatch(sbPrivateKey.ToString(), sbPublicKey.ToString());
.WriteLine("Rsa.KeyMatch returns {0} (expecting 0)", n);
Console.Assert(0 == n, "Rsa.KeyMatch failed."); Debug
Rsa Class
CryptoSysPKI Namespace
Verify that a pair of “internal” RSA private and public key strings are matched.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
KeyMatch(String, String) | Verify that a pair of “internal” RSA private and public key strings are matched. |
KeyMatch(StringBuilder, StringBuilder) | Verify that a pair of “internal” RSA private and public key strings are matched. |
public static int KeyMatch(
,
StringBuilder sbPrivateKey
StringBuilder sbPublicKey)
Internal RSA private key string
Internal RSA public key string
Int32
0=valid key pair, or negative error
code
= Rsa.ReadPublicKey(pubkeyFile);
StringBuilder sbPublicKey = Rsa.ReadPrivateKey(prikeyFile, "password");
StringBuilder sbPrivateKey int n = Rsa.KeyMatch(sbPrivateKey, sbPublicKey);
Rsa Class
CryptoSysPKI Namespace
Extract a base64-encoded RSA key value from internal key string
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string KeyValue(
string keyString,
string fieldName
)
Public or private key in internal string format
Name of field to be extracted: "Modulus"
or
"Exponent"
String
Value encoded in base64 or an empty string on error
The output is a continuous string of base64 characters suitable for a
<RSAKeyValue>
node in an XML-DSIG document.
Rsa Class
CryptoSysPKI Namespace
Note: This API is now obsolete. Generate an RSA public/private key pair [DEPRECATED].
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
MakeKeys(String, String, Int32, Rsa.PublicExponent, Int32, String, Rsa.PbeOptions, Boolean, Byte[]) | Obsolete. Generate an RSA public/private key pair [DEPRECATED]. |
MakeKeys(String, String, String, Int32, Rsa.PublicExponent, Rsa.PbeOptions, String, Rsa.Format, Boolean) | Generate an RSA public/private key pair. |
MakeKeys(String, String, Int32, Rsa.PublicExponent, Int32, String, CipherAlgorithm, HashAlgorithm, Rsa.Format, Boolean) | Obsolete. Generate an RSA public/private key pair with extended options for encrypting private key [DEPRECATED]. |
[ObsoleteAttribute("Use Rsa.MakeKeys(String, String, String, Int32, Rsa.PublicExponent, Rsa.PbeOptions, String, Rsa.Format, Boolean) instead",
false)]
public static int MakeKeys(
string publicKeyFile,
string privateKeyFile,
int bits,
.PublicExponent exponent,
Rsaint iterCount,
string password,
.PbeOptions cryptOption,
Rsabool showProgress = false,
byte[] seedBytes = null
)
Output filename for public key
Output filename for (encrypted) private key
Required key modulus size in bits (min 96)
Exponent (Fermat Prime)
Iteration count for encrypted private key
Password string for encrypted private key
Option to specify encryption algorithm for private key
Indicate progress in console
(optional) User-supplied-entropy in byte format
Int32
Zero if successful or non-zero error
code
Rsa Class
CryptoSysPKI Namespace
Generate an RSA public/private key pair.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
MakeKeys(String, String, Int32, Rsa.PublicExponent, Int32, String, Rsa.PbeOptions, Boolean, Byte[]) | Obsolete. Generate an RSA public/private key pair [DEPRECATED]. |
MakeKeys(String, String, String, Int32, Rsa.PublicExponent, Rsa.PbeOptions, String, Rsa.Format, Boolean) | Generate an RSA public/private key pair. |
MakeKeys(String, String, Int32, Rsa.PublicExponent, Int32, String, CipherAlgorithm, HashAlgorithm, Rsa.Format, Boolean) | Obsolete. Generate an RSA public/private key pair with extended options for encrypting private key [DEPRECATED]. |
public static int MakeKeys(
string publicKeyFile,
string privateKeyFile,
string password,
int bits,
.PublicExponent exponent = Rsa.PublicExponent.Exp_EQ_65537,
Rsa.PbeOptions pbes = Rsa.PbeOptions.Default,
Rsastring paramString = "",
.Format fileFormat = Rsa.Format.Default,
Rsabool showProgress = false
)
Output filename for public key
Output filename for (encrypted) private key
Password for encrypted private key
Required key modulus size in bits (min 96)
Exponent [default=65537=F4]
Encryption scheme to encrypt private key [default=pbeWithSHAAnd3-KeyTripleDES-CBC from PKCS#12]
Optional parameters. A set of attribute name=value pairs separated by a semicolon “;” (see remarks)
Format to save file [default = DER binary]
Indicate progress in console
Int32
Zero if successful or non-zero error
code
Valid name-value pairs for paramString
are:
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 ]. |
Valid values for hmac-name are one of
{hmacWithSHA1, hmacWithSHA224, hmacWithSHA256, hmacWithSHA384, hmacWithSHA512}
.
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,
.PbeOptions.Pbe_Pbkdf2_aes128_CBC, "count=3000;prf=hmacWithSHA256", Rsa.Format.PEM, true);
Rsa.WriteLine("Rsa.MakeKeys returned {0}", n);
Console.Assert(n == 0, "Failed to create RSA key pair");
Debug.WriteLine("Created public/private key pair OK"); Console
Rsa Class
CryptoSysPKI Namespace
Note: This API is now obsolete. Generate an RSA public/private key pair with extended options for encrypting private key [DEPRECATED].
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
MakeKeys(String, String, Int32, Rsa.PublicExponent, Int32, String, Rsa.PbeOptions, Boolean, Byte[]) | Obsolete. Generate an RSA public/private key pair [DEPRECATED]. |
MakeKeys(String, String, String, Int32, Rsa.PublicExponent, Rsa.PbeOptions, String, Rsa.Format, Boolean) | Generate an RSA public/private key pair. |
MakeKeys(String, String, Int32, Rsa.PublicExponent, Int32, String, CipherAlgorithm, HashAlgorithm, Rsa.Format, Boolean) | Obsolete. Generate an RSA public/private key pair with extended options for encrypting private key [DEPRECATED]. |
[ObsoleteAttribute("Use Rsa.MakeKeys(String, String, String, Int32, Rsa.PublicExponent, Rsa.PbeOptions, String, Rsa.Format, Boolean) instead",
false)]
public static int MakeKeys(
string publicKeyFile,
string privateKeyFile,
int bits,
.PublicExponent exponent,
Rsaint iterCount,
string password,
,
CipherAlgorithm cipherAlg,
HashAlgorithm hashAlg.Format fileFormat,
Rsabool showProgress
)
Output filename for public key
Output filename for (encrypted) private key
Required key modulus size in bits (min 96)
Exponent (Fermat Prime)
Iteration count for encrypted private key
Password string for encrypted private key
Block cipher to use for encryption scheme [default = des-ede3-cbc]
Hash function to use in PRF HMAC algorithm [default = hmacWithSHA1]
Format to save file [default = DER binary]
Indicate progress in console
Int32
Zero if successful or non-zero error
code
The private key is saved in encrypted PKCS#8 format using the PBES2 encryption scheme from PKCS#5 with key derivation function PBKDF2.
Rsa Class
CryptoSysPKI Namespace
Convert an internal private key string into a public one.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static StringBuilder PublicKeyFromPrivate(
StringBuilder sbKeyString)
StringBuilder containing private key in “internal” format
StringBuilder
StringBuilder containing an internal representation of the public key;
or an empty StringBuilder if error
This returns a StringBuilder, not a string. Use sb.ToString() to obtain a string.
Rsa Class
CryptoSysPKI Namespace
Carry out RSA transformation using private key.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
RawPrivate(Byte[], String) | Carry out RSA transformation using private key. |
RawPrivate(Byte[], String, Int32) | Carry out RSA transformation using private key (with specialist options). |
public static byte[] RawPrivate(
byte[] data,
string privateKeyStr
)
Data (must be same byte length as key modulus)
Private key in internal string format
Byte[]
Transformed data
Rsa Class
CryptoSysPKI Namespace
Carry out RSA transformation using private key (with specialist options).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
RawPrivate(Byte[], String) | Carry out RSA transformation using private key. |
RawPrivate(Byte[], String, Int32) | Carry out RSA transformation using private key (with specialist options). |
public static byte[] RawPrivate(
byte[] data,
string privateKeyStr,
int options
)
Data (must be same byte length as key modulus)
Private key in internal string format
Specialist options value
Byte[]
Transformed data
Rsa Class
CryptoSysPKI Namespace
Carry out RSA transformation using public key.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
RawPublic(Byte[], String) | Carry out RSA transformation using public key. |
RawPublic(Byte[], String, Int32) | Carry out RSA transformation using public key (with specialist options). |
public static byte[] RawPublic(
byte[] data,
string publicKeyStr
)
Data (must be same byte length as key modulus)
Public key in internal string format
Byte[]
Transformed data
Rsa Class
CryptoSysPKI Namespace
Carry out RSA transformation using public key (with specialist options).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
RawPublic(Byte[], String) | Carry out RSA transformation using public key. |
RawPublic(Byte[], String, Int32) | Carry out RSA transformation using public key (with specialist options). |
public static byte[] RawPublic(
byte[] data,
string publicKeyStr,
int options
)
Data (must be same byte length as key modulus)
Public key in internal string format
Specialist options value
Byte[]
Transformed data
Rsa Class
CryptoSysPKI Namespace
Note: This API is now obsolete. Read encrypted private key file into internal string format.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[ObsoleteAttribute("Use Rsa.ReadPrivateKey() instead", false)]
public static StringBuilder ReadEncPrivateKey(
string privateKeyFile,
string password
)
filename of a binary BER-encoded encrypted private key info file
password for key file
StringBuilder
StringBuilder containing an internal representation of the private key;
or an empty StringBuilder if error
This returns a StringBuilder, not a string. Use sb.ToString() to obtain a string.
Rsa Class
CryptoSysPKI Namespace
Read from a file or string containing a private key into an “internal” private key string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static StringBuilder ReadPrivateKey(
string privateKeyFile,
string password = ""
)
Name of private key file or a PEM String containing the key
Password for private key, if encrypted
StringBuilder
StringBuilder containing an internal representation of the private key;
or an empty StringBuilder if error
This returns a StringBuilder, not a string, to allow secure wiping. Use sb.ToString() to obtain a string.
= Rsa.ReadPrivateKey("AlicePrivRSASign.p8e", "password");
StringBuilder sbPrivateKey .Assert(sbPrivateKey.Length > 0, "Rsa.ReadPrivateKey Failed");
Debug.WriteLine("Key length={0} bits", Rsa.KeyBits(sbPrivateKey.ToString())); Console
Rsa Class
CryptoSysPKI Namespace
Note: This API is now obsolete. Read a private key directly from an encrypted PFX/PKCS-12 file into an “internal” private key string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[ObsoleteAttribute("Use Rsa.ReadPrivateKey() instead", false)]
public static StringBuilder ReadPrivateKeyFromPFX(
string pfxFile,
string password
)
PKCS-12 filename
Password for PFX file
StringBuilder
StringBuilder containing an internal representation of the private key;
or an empty StringBuilder if error
This returns a StringBuilder, not a string. Use sb.ToString() to obtain a string.
Rsa Class
CryptoSysPKI Namespace
Note: This API is now obsolete. Read from an (unencrypted) PKCS-8 private key info file into a private key string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[ObsoleteAttribute("Use Rsa.ReadPrivateKey() instead", false)]
public static StringBuilder ReadPrivateKeyInfo(
string prikeyinfoFile
)
Name of file
StringBuilder
StringBuilder containing an internal representation of the private key;
or an empty StringBuilder if error
This returns a StringBuilder, not a string. Use sb.ToString() to obtain a string.
Rsa Class
CryptoSysPKI Namespace
Read from a file or string containing a public key into an “internal” public key string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static StringBuilder ReadPublicKey(
string certOrPublicKeyFile
)
Name of X.509 certificate or public key file or a PEM String containing the key
StringBuilder
StringBuilder containing an internal representation of the public key;
or an empty StringBuilder if error
This returns a StringBuilder, not a string. Use sb.ToString() to obtain a string.
// Read an RSA public key and save in a different format
string pubkeyFile = "AlicePubRSA.pub";
= Rsa.ReadPublicKey(pubkeyFile);
StringBuilder sbPublicKey .Assert(sbPublicKey.Length > 0, "Rsa.ReadPublicKey Failed");
Debugint n = Rsa.SavePublicKey("AlicePubRSA_new", sbPublicKey.ToString(), Rsa.Format.SSL);
.WriteLine("Rsa.SavePublicKey returns {0} (expecting 0)", n); Console
Rsa Class
CryptoSysPKI Namespace
Save an internal RSA key string to an encrypted key file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int SaveEncKey(
string outputFile,
string privateKey,
string password,
.PbeOptions pbeOption,
Rsastring paramString = "",
.Format format = Rsa.Format.Default
Rsa)
Name of output file to be created
The private RSA key as an internal key string.
Password to be used for the encrypted key file.
Encryption scheme to encrypt private key [default =
pbeWithSHAAnd3-KeyTripleDES-CBC
from PKCS#12]
Optional parameters. A set of attribute name=value pairs separated by a semicolon “;” (see remarks).
File format
Int32
If successful, the return value is zero; otherwise it returns a nonzero
error code
Valid name-value pairs for paramString
are:
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 ]. |
Valid values for hmac-name are one of
{hmacWithSHA1, hmacWithSHA224, hmacWithSHA256, hmacWithSHA384, hmacWithSHA512}
.
Rsa Class
CryptoSysPKI Namespace
Save a private key string to a PKCS-8 EncryptedPrivateKeyInfo file [DEPRECATED].
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
SaveEncPrivateKey(String, String, Int32, String, Rsa.PbeOptions, Rsa.Format) | Save a private key string to a PKCS-8 EncryptedPrivateKeyInfo file [DEPRECATED]. |
SaveEncPrivateKey(String, String, Int32, String, CipherAlgorithm, HashAlgorithm, Rsa.Format) | Save a private key string to a PKCS-8 EncryptedPrivateKeyInfo file using PBES2 algorithm [DEPRECATED]. |
public static int SaveEncPrivateKey(
string outputFile,
string privateKey,
int iterationCount,
string password,
.PbeOptions pbeOption,
Rsa.Format format
Rsa)
Name of file to create
Private key in internal format
Iteration count to be used when encrypting file
Password string
Type of password-based encryption to use [default = pbeWithSHAAnd3-KeyTripleDES-CBC]
File format
Int32
If successful, the return value is zero; otherwise it returns a nonzero
error code
Rsa Class
CryptoSysPKI Namespace
Save a private key string to a PKCS-8 EncryptedPrivateKeyInfo file using PBES2 algorithm [DEPRECATED].
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
SaveEncPrivateKey(String, String, Int32, String, Rsa.PbeOptions, Rsa.Format) | Save a private key string to a PKCS-8 EncryptedPrivateKeyInfo file [DEPRECATED]. |
SaveEncPrivateKey(String, String, Int32, String, CipherAlgorithm, HashAlgorithm, Rsa.Format) | Save a private key string to a PKCS-8 EncryptedPrivateKeyInfo file using PBES2 algorithm [DEPRECATED]. |
public static int SaveEncPrivateKey(
string outputFile,
string privateKey,
int iterationCount,
string password,
,
CipherAlgorithm cipherAlg,
HashAlgorithm hashAlg.Format format
Rsa)
Name of file to create
Private key in internal format
Iteration count to be used when encrypting file
Password string
Block cipher to use for encryption scheme [default = des-ede3-cbc]
Hash function to use in PRF HMAC algorithm [default = hmacWithSHA1]
File format
Int32
If successful, the return value is zero; otherwise it returns a nonzero
error code
Rsa Class
CryptoSysPKI Namespace
Save a private key string to an (unencrypted) PKCS-8 private key info file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int SavePrivateKeyInfo(
string outputFile,
string privateKey,
.Format format
Rsa)
Name of file to create
Private key in internal format
File format
Int32
If successful, the return value is zero; otherwise it returns a nonzero
error code
Do not use for a production key.
Rsa Class
CryptoSysPKI Namespace
Save a public key string to PKCS-1 public key file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int SavePublicKey(
string outputFile,
string publicKey,
.Format format
Rsa)
Name of file to create
Public key in internal format
File format
Int32
If successful, the return value is zero; otherwise it returns a nonzero
error code
Rsa Class
CryptoSysPKI Namespace
Create an XML string representation of an RSA internal key string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
ToXMLString(String, Rsa.XmlOptions) | Create an XML string representation of an RSA internal key string. |
ToXMLString(String, String, Rsa.XmlOptions) | Create an XML string representation of an RSA internal key string with option to add a namespace prefix. |
public static string ToXMLString(
string intKeyString,
.XmlOptions options
Rsa)
Internal key string
Option flags: set as zero for defaults.
String
XML string or empty string on error
Rsa Class
CryptoSysPKI Namespace
Create an XML string representation of an RSA internal key string with option to add a namespace prefix.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
ToXMLString(String, Rsa.XmlOptions) | Create an XML string representation of an RSA internal key string. |
ToXMLString(String, String, Rsa.XmlOptions) | Create an XML string representation of an RSA internal key string with option to add a namespace prefix. |
public static string ToXMLString(
string intKeyString,
string prefix,
.XmlOptions options
Rsa)
Internal key string
Prefix to add to elements, e.g. "ds"
or
"ds:"
.
Option flags: set as zero for defaults.
String
XML string or empty string on error
Use this extended function to add a namespace prefix to all elements in the XML output; for example, <ds:RSAKeyValue>. Note that it’s up to the user to map the prefix to a URI somewhere in the final XML document.
Rsa Class
CryptoSysPKI Namespace
Signature creation and verification
System.Object
CryptoSysPKI.Sig
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Sig
The Sig type exposes the following members.
Name | Description |
---|---|
GetHashAlgFromSigAlg | Get the hash algorithm used in the signature algorithm. |
SignData | Compute a signature value over data in a byte array. |
SignDigest | Compute a signature value over a message digest value. |
SignFile | Compute a signature value over binary data in a file. |
VerifyData | Verify a signature value over data in a byte array. |
VerifyDigest | Verify a signature value over a message digest value of data. |
VerifyFile | Verify a signature value over data in a file. |
Get the hash algorithm used in the signature algorithm.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static HashAlgorithm GetHashAlgFromSigAlg(
SigAlgorithm sigAlg)
Signature algorithm
HashAlgorithm
Hash algorithm used in sigAlg
Sig Class
CryptoSysPKI Namespace
Compute a signature value over a message digest value.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string SignDigest(
byte[] digest,
string privateKeyFile,
string password,
,
SigAlgorithm sigAlg.SigOptions sigOpts = Sig.SigOptions.Default,
Sig.Encoding sigEncoding = Sig.Encoding.Default
Sig)
digest value in a byte array
Name of private key file (or a string containing the key in PEM format, or an internal private key)
Password for the private key, if encrypted
Signature algorithm to be used
(optional) Options for ECDSA and RSA-PSS signatures
Optional encodings for output [default=base64]
String
The encoded signature, or an empty string on error
Sig Class
CryptoSysPKI Namespace
Compute a signature value over binary data in a file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string SignFile(
string dataFile,
string privateKeyFile,
string password,
,
SigAlgorithm sigAlg.SigOptions sigOpts = Sig.SigOptions.Default,
Sig.Encoding sigEncoding = Sig.Encoding.Default
Sig)
Name of input file containing data to be signed
Name of private key file (or a string containing the key in PEM format, or an internal private key)
Password for the private key, if encrypted
Signature algorithm to be used
(optional) Options for ECDSA and RSA-PSS signatures
Optional encodings for output [default=base64]
String
The encoded signature, or an empty string on error
Sig Class
CryptoSysPKI Namespace
Verify a signature value over data in a byte array.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int VerifyData(
string sigStr,
byte[] data,
string certOrKeyFile,
,
SigAlgorithm sigAlg.VerifyOpts opts = Sig.VerifyOpts.Default
Sig)
Encoded signature value
Input data to be verified
The X.509 certificate or public key file name (or a string containing the certificate or key in PEM format or base64 representation, or an internal key string).
Signature algorithm used to create signature.
(optional) Advanced options for RSA-PSS only.
Int32
Zero (0) if the signature is valid; otherwise a negative error code.
Any valid encodings of the signature value are detected automatically.
string certFile = "AliceRSASignByCarl.cer"; // Used to verify signature
// Signed data: a byte array with ASCII string "abc"
byte[] b = System.Text.Encoding.Default.GetBytes("abc");
string sig = // Alice/'abc'/SHA-1
"YK1aePtKQDDsVCyJdM0V9VOE6DZVTO3ZoyLV9BNcYmep0glwxU5mUQcLAUTUOETImTIN2Pp4Gffr" +
"xqdxUoczLshnXBNhg7P4ofge+WlBgmcTCnVv27LHHZpmdEbjTg6tnPMb+2b4FvMZ0LfkMKXyiRVTmG4A" +
"NyAmHH6QIsDZ8R8=";
int n = Sig.VerifyData(sig, b, certFile, SigAlgorithm.Default);
.WriteLine("Sig.VerifyData returns " + n + " (expecting 0)");
Console.Assert(0 == n, "Sig.VerifyData failed"); Debug
Sig Class
CryptoSysPKI Namespace
Verify a signature value over a message digest value of data.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int VerifyDigest(
string sigStr,
byte[] digest,
string certOrKeyFile,
,
SigAlgorithm sigAlg.VerifyOpts opts = Sig.VerifyOpts.Default
Sig)
Containing the encoded signature value
Byte array containing the message digest value of the data to be verified
Specifying the X.509 certificate or public key file name (or a string containing the certificate or key in PEM format or base64 representation, or an internal key string).
Signature algorithm used to create signature.
Advanced options for RSA-PSS only (optional)
Int32
Zero (0) if the signature is valid; otherwise a negative error code.
Any valid encodings of the signature value are detected automatically.
Sig Class
CryptoSysPKI Namespace
Verify a signature value over data in a file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int VerifyFile(
string sigStr,
string dataFile,
string certOrKeyFile,
,
SigAlgorithm sigAlg.VerifyOpts opts = Sig.VerifyOpts.Default
Sig)
Containing the encoded signature value
Name of file containing data to be verified
Specifying the X.509 certificate or public key file name (or a string containing the certificate or key in PEM format or base64 representation, or an internal key string).
Signature algorithm used to create signature.
Advanced options for RSA-PSS only (optional)
Int32
Zero (0) if the signature is valid; otherwise a negative error code.
Any valid encodings of the signature value are detected automatically.
Sig Class
CryptoSysPKI Namespace
S/MIME utilities
System.Object
CryptoSysPKI.Smime
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Smime
The Smime type exposes the following members.
Name | Description |
---|---|
Extract | Extract the body from an S/MIME entity. |
Query | Query an S/MIME entity for selected information. |
Wrap | Wrap a CMS object in an S/MIME entity. |
Extract the body from an S/MIME entity.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int Extract(
string outputFile,
string inputFile,
.Options opts
Smime)
Name of output file to be created
Name of input file containing S/MIME entity
Options
Int32
A positive number giving the size of the output file in bytes; otherwise
it returns an error code
This is designed to extract the body from an S/MIME entity with a
content type of application/pkcs7-mime
with base64 or
binary transfer encoding. In practice, it will extract the body from
almost any type of S/MIME (or MIME) file, except one with
quoted-printable transfer encoding. By default the output is encoded in
binary. Use the EncodeBase64
option to encode the output in base64.
Smime Class
CryptoSysPKI Namespace
Query an S/MIME entity for selected information.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string Query(
string inputFile,
string query
)
Name of file containing S/MIME entity
Query string (case insensitive)
String
String containing the result or an empty string if not found or
error.
Valid queries are:
"content-type" |
Value of Content-Type,
e.g. "application/pkcs7-mime" . |
---|---|
"smime-type" |
Value of smime-type parameter of Content-Type, e.g. ,
e.g. "enveloped-data" . |
"encoding" |
Value of Content-Transfer-Encoding, e.g. “base64”. |
"name" |
Value of name parameter of Content-Type, e.g. “smime.p7m” |
"filename" |
Value of filename parameter of Content-Disposition, e.g. “smime.p7m”. |
Smime Class
CryptoSysPKI Namespace
Wrap a CMS object in an S/MIME entity.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int Wrap(
string outputFile,
string inputFile,
.Options opts
Smime)
Output file to be created
Input file containing CMS object
Options
Int32
A positive number giving the size of the output file in bytes; otherwise
it returns an error code
The input file is expected to be a binary CMS object of type enveloped-data, signed-data or compressed-data; otherwise it is an error. The type of input file is detected automatically. By default the body is encoded in base64 encoding. Use the EncodeBinary option to encode the body in binary.
Smime Class
CryptoSysPKI Namespace
Triple DES Cipher (3DES, TDEA) [deprecated: use Cipher() class with CipherAlgorithm.Tdea instead]
System.Object
CryptoSysPKI.Tdea
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Tdea
The Tdea type exposes the following members.
Name | Description |
---|---|
Decrypt(Byte[], Byte[], Mode, Byte[]) | Decrypt data in byte array. |
Decrypt(String, String, Mode, String) | Decrypt hex-encoded data string. |
Decrypt(String, String, Mode, String, EncodingBase) | Decrypt encoded data string. |
Encrypt(Byte[], Byte[], Mode, Byte[]) | Encrypt data in byte array. |
Encrypt(String, String, Mode, String) | Encrypt hex-encoded data string. |
Encrypt(String, String, Mode, String, EncodingBase) | Encrypt encoded data string. |
FileDecrypt(String, String, Byte[], Mode, Byte[]) | Decrypt a file. |
FileDecrypt(String, String, String, Mode, String) | Decrypt a file passing key and IV as hex strings. |
FileEncrypt(String, String, Byte[], Mode, Byte[]) | Encrypt a file. |
FileEncrypt(String, String, String, Mode, String) | Encrypt a file passing key and IV as hex strings. |
Name | Description |
---|---|
BlockSize | Block size in bytes |
Decrypt data in byte array.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Decrypt(Byte[], Byte[], Mode, Byte[]) | Decrypt data in byte array. |
Decrypt(String, String, Mode, String) | Decrypt hex-encoded data string. |
Decrypt(String, String, Mode, String, EncodingBase) | Decrypt encoded data string. |
public static byte[] Decrypt(
byte[] input,
byte[] key,
,
Mode modebyte[] iv
)
Input data
Key of exactly 24 bytes (192 bits)
Cipher Mode
IV of exactly 8 bytes or null
for ECB mode
Byte[]
Decrypted data in byte array or empty array on error
For ECB and CBC modes, input data length must be an exact multiple of the block length
Tdea Class
CryptoSysPKI Namespace
Decrypt hex-encoded data string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Decrypt(Byte[], Byte[], Mode, Byte[]) | Decrypt data in byte array. |
Decrypt(String, String, Mode, String) | Decrypt hex-encoded data string. |
Decrypt(String, String, Mode, String, EncodingBase) | Decrypt encoded data string. |
public static string Decrypt(
string inputHex,
string keyHex,
,
Mode modestring ivHex
)
Hex-encoded input data
Hex-encoded key representing exactly 24 bytes (192 bits)
Cipher Mode
Hex-encoded IV representing exactly 8 bytes or ""
for
ECB mode
String
Decrypted data in hex-encoded string or empty string on error
For ECB and CBC modes, the length of the decoded input bytes must be an exact multiple of the block length
Tdea Class
CryptoSysPKI Namespace
Decrypt encoded data string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Decrypt(Byte[], Byte[], Mode, Byte[]) | Decrypt data in byte array. |
Decrypt(String, String, Mode, String) | Decrypt hex-encoded data string. |
Decrypt(String, String, Mode, String, EncodingBase) | Decrypt encoded data string. |
public static string Decrypt(
string inputStr,
string keyStr,
,
Mode modestring ivStr,
EncodingBase encodingBase)
Encoded input data
Encoded key representing exactly 24 bytes (192 bits)
Cipher Mode
Encoded IV representing exactly 8 bytes or ""
for ECB
mode
Type of encoding used
String
Decrypted data in encoded string or empty string on error
For ECB and CBC modes, the length of the decoded input bytes must be an exact multiple of the block length
Tdea Class
CryptoSysPKI Namespace
Encrypt data in byte array.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Encrypt(Byte[], Byte[], Mode, Byte[]) | Encrypt data in byte array. |
Encrypt(String, String, Mode, String) | Encrypt hex-encoded data string. |
Encrypt(String, String, Mode, String, EncodingBase) | Encrypt encoded data string. |
public static byte[] Encrypt(
byte[] input,
byte[] key,
,
Mode modebyte[] iv
)
Input data
Key of exactly 24 bytes (192 bits)
Cipher Mode
IV of exactly 8 bytes or null
for ECB mode
Byte[]
Ciphertext in byte array or empty array on error
For ECB and CBC modes, input data length must be an exact multiple of the block length
Tdea Class
CryptoSysPKI Namespace
Encrypt hex-encoded data string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Encrypt(Byte[], Byte[], Mode, Byte[]) | Encrypt data in byte array. |
Encrypt(String, String, Mode, String) | Encrypt hex-encoded data string. |
Encrypt(String, String, Mode, String, EncodingBase) | Encrypt encoded data string. |
public static string Encrypt(
string inputHex,
string keyHex,
,
Mode modestring ivHex
)
Hex-encoded input data
Hex-encoded key representing exactly 24 bytes (192 bits)
Cipher Mode
Hex-encoded IV representing exactly 8 bytes or ""
for
ECB mode
String
Ciphertext in hex-encoded string or empty string on error
For ECB and CBC modes, the length of the decoded input bytes must be an exact multiple of the block length
Tdea Class
CryptoSysPKI Namespace
Encrypt encoded data string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
Encrypt(Byte[], Byte[], Mode, Byte[]) | Encrypt data in byte array. |
Encrypt(String, String, Mode, String) | Encrypt hex-encoded data string. |
Encrypt(String, String, Mode, String, EncodingBase) | Encrypt encoded data string. |
public static string Encrypt(
string inputStr,
string keyStr,
,
Mode modestring ivStr,
EncodingBase encodingBase)
Encoded input data
Encoded key representing exactly 24 bytes (192 bits)
Cipher Mode
Encoded IV representing exactly 8 bytes or ""
for ECB
mode
Type of encoding used
String
Ciphertext in hex-encoded string or empty string on error
For ECB and CBC modes, the length of the decoded input bytes must be an exact multiple of the block length
Tdea Class
CryptoSysPKI Namespace
Decrypt a file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
FileDecrypt(String, String, Byte[], Mode, Byte[]) | Decrypt a file. |
FileDecrypt(String, String, String, Mode, String) | Decrypt a file passing key and IV as hex strings. |
public static int FileDecrypt(
string fileOut,
string fileIn,
byte[] key,
,
Mode modebyte[] iv
)
Name of output file to be created or overwritten
Name of input file
Key of exactly 8 bytes (64 bits)
Cipher Mode
IV of exactly 8 bytes or null
for ECB mode
Int32
0 if successful or non-zero error
code
fileOut
and fileIn
must
not be the same
Tdea Class
CryptoSysPKI Namespace
Decrypt a file passing key and IV as hex strings.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
FileDecrypt(String, String, Byte[], Mode, Byte[]) | Decrypt a file. |
FileDecrypt(String, String, String, Mode, String) | Decrypt a file passing key and IV as hex strings. |
public static int FileDecrypt(
string fileOut,
string fileIn,
string keyHex,
,
Mode modestring ivHex
)
Name of output file to be created or overwritten
Name of input file
Hex-encoded key of exact length
Cipher Mode
Hex-encoded IV or ""
for ECB mode
Int32
0 if successful or non-zero error
code
fileOut
and fileIn
must
not be the same. The output file is in binary
format.
Tdea Class
CryptoSysPKI Namespace
Encrypt a file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
FileEncrypt(String, String, Byte[], Mode, Byte[]) | Encrypt a file. |
FileEncrypt(String, String, String, Mode, String) | Encrypt a file passing key and IV as hex strings. |
public static int FileEncrypt(
string fileOut,
string fileIn,
byte[] key,
,
Mode modebyte[] iv
)
Name of output file to be created or overwritten
Name of input file
Key of exactly 24 bytes (192 bits)
Cipher Mode
IV of exactly 8 bytes or null
for ECB mode
Int32
0 if successful or non-zero error
code
fileOut
and fileIn
must
not be the same
Tdea Class
CryptoSysPKI Namespace
Encrypt a file passing key and IV as hex strings.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
Name | Description |
---|---|
FileEncrypt(String, String, Byte[], Mode, Byte[]) | Encrypt a file. |
FileEncrypt(String, String, String, Mode, String) | Encrypt a file passing key and IV as hex strings. |
public static int FileEncrypt(
string fileOut,
string fileIn,
string keyHex,
,
Mode modestring ivHex
)
Name of output file to be created or overwritten
Name of input file
Hex-encoded key of exact length
Cipher Mode
Hex-encoded IV or ""
for ECB mode
Int32
0 if successful or non-zero error
code
fileOut
and fileIn
must
not be the same. The output file is in binary
format.
Tdea Class
CryptoSysPKI Namespace
Block size in bytes
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public const int BlockSize = 8
Int32
Tdea Class
CryptoSysPKI Namespace
Data Wiping Functions
System.Object
CryptoSysPKI.Wipe
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Wipe
The Wipe type exposes the following members.
Name | Description |
---|---|
Data | Zeroise data in memory. |
File | Securely wipe and delete a file with options. |
String | Zeroise a StringBuilder. |
Zeroise data in memory.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static bool Data(
byte[] data
)
data to be wiped
Boolean
true
if successful; false
if fails
byte[] b = System.Text.Encoding.Default.GetBytes("Secret data");
.WriteLine("Before Wipe.Data, b = [{0}]", System.Text.Encoding.Default.GetString(b));
Console.Data(b);
Wipe.WriteLine("After Wipe.Data, b = [{0}]", System.Text.Encoding.Default.GetString(b));
Console// Before Wipe.Data, b = [Secret data]
// After Wipe.Data, b = [ ]
Wipe Class
CryptoSysPKI Namespace
Securely wipe and delete a file with options.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static bool File(
string fileName,
.Options opts = Wipe.Options.Default
Wipe)
Name of file to be wiped
Options (optional, default = DOD 7-pass)
Boolean
true
if successful; false
if fails
bool isok = Wipe.File("ImportantSecret.txt");
.Assert(isok, "Failed to wipe file"); Debug
Wipe Class
CryptoSysPKI Namespace
X.509 Certificate Functions
System.Object
CryptoSysPKI.X509
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class X509
The X509 type exposes the following members.
Name | Description |
---|---|
CertExpiresOn | Return date and time certificate expires. |
CertIssuedOn | Return date and time certificate was issued. |
CertIssuerName | Get the issuer name of an X.509 certificate. |
CertIsValidNow | Verify that an X.509 certificate is currently valid as per system clock. |
CertRequest | Create a PKCS #10 certificate signing request (CSR). |
CertSerialNumber | Return serial number in hex format. |
CertSubjectName | Get the subject name of an X.509 certificate. |
CertThumb | Calculate the thumbprint (message digest hash) of an X.509 certificate. |
CheckCertInCRL | Check whether an X.509 certificate has been revoked in a Certificate Revocation List (CRL). |
GetCertCountInP7Chain | Return number of certificates in a PKCS-7 “certs-only” certificate chain file. |
GetCertFromP7Chain | Extract an X.509 certificate from a PKCS-7 “certs-only” certificate chain file, saving the output directly as a new file. |
GetCertFromPFX | Extract an X.509 certificate from a PKCS-12 PFX/.p12 file, saving the output directly as a new file. |
GetP7ChainFromPFX | Extract all X.509 certificates from a PKCS-12 PFX/.p12 file, saving the output directly as a new PKCS-7 “certs-only” certificate chain file. |
HashIssuerAndSN | Create a message digest of the Issuer’s name and the cert serial number. |
KeyUsageFlags | Returns a bitfield containing the keyUsage flags. |
MakeCert | Create a new X.509 certificate using subject’s public key and issuer’s private key files with signature options. |
MakeCertSelf | Create a self-signed X.509 certificate with signature options. |
MakeCRL | Create an X.509 Certificate Revocation List (CRL). |
QueryCert | Query an X.509 certificate file for selected information. |
ReadCertStringFromP7Chain | Read an X.509 certificate into a base64 string from PKCS-7 “certs-only” data. |
ReadCertStringFromPFX | Read an X.509 certificate into a base64 string from PKCS-12 PFX/.p12 data. |
ReadStringFromFile | Create a base64 string representation of a X.509 certificate file. |
SaveFileFromString | Create a new X.509 certificate file from a base64 string representation. |
TextDump | Dump details of an X.509 certificate or a X.509 certificate revocation list (CRL) or a PKCS-10 certificate signing request (CSR) to a text file. |
TextDumpToString | Dump details of an X.509 certificate or a X.509 certificate revocation list (CRL) or a PKCS-10 certificate signing request (CSR) to a string. |
ValidatePath | Validate a certificate path. |
VerifyCert | Verify that an X.509 certificate has been signed by its issuer. |
Name | Description |
---|---|
Expired | Return value from X509.CertIsValidNow indicating that the
certificate has expired (EXPIRED_ERROR ). |
Failure | Return value from X509.VerifyCert
indicating failure (SIGNATURE_ERROR ). |
Invalid | Return value from X509.ValidatePath
indicating that the certificate path is invalid
(CERT_PATH_ERROR ). |
Revoked | Return value from X509.CheckCertInCRL indicating that the
certificate is revoked (REVOCATION_ERROR ). |
Return date and time certificate expires.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string CertExpiresOn(
string certFile
)
Filename of certificate file (or its base64 representation)
String
Date and time in ISO format or Empty string if error
X509 Class
CryptoSysPKI Namespace
Return date and time certificate was issued.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string CertIssuedOn(
string certFile
)
Filename of certificate file (or its base64 representation)
String
Date and time in ISO format or Empty string if error
X509 Class
CryptoSysPKI Namespace
Get the issuer name of an X.509 certificate.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string CertIssuerName(
string certFile,
string delimiter = ";"
)
Filename of certificate file (or its base64 representation)
Optional character for delimiter [default = semicolon “;”]
String
Issuer name or Empty string if error
Use X509.QueryCert with query
"issuerName"
for more output options.
X509 Class
CryptoSysPKI Namespace
Verify that an X.509 certificate is currently valid as per system clock.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static bool CertIsValidNow(
string certFile
)
Filename of certificate file (or its base64 representation)
Boolean
True if certificate is currently valid, otherwise false
X509 Class
CryptoSysPKI Namespace
Create a PKCS #10 certificate signing request (CSR).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int CertRequest(
string reqFile,
string privateKeyFile,
string distName,
string extensions,
string password,
,
SigAlgorithm sigAlg.CsrOptions opts
X509)
Name of Certificate Signing Request file to be created
Name of subject’s encrypted private key file
Specifying the subject’s distinguished name as a set of attribute key=value pairs separated with semi-colons (;). See Specifying Distinguished Names
A list of attribute-value pairs to be included in an
extensionRequest
field. See X.509
Extensions
password for Subject’s encrypted private key file
Signature algorithm (must match key type)
Option flags: set as zero for defaults.
Int32
Zero if successful or a non-zero error
code
An ECC key must use an ECDSA signature algorithm, and an RSA key must use an RSA signature algorithm.
X509 Class
CryptoSysPKI Namespace
Return serial number in hex format.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string CertSerialNumber(
string certFile
)
Filename of certificate file (or its base64 representation)
String
Serial number in hex format or Empty string if error
X509 Class
CryptoSysPKI Namespace
with query serialNumber
.
Get the subject name of an X.509 certificate.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string CertSubjectName(
string certFile,
string delimiter = ";"
)
Filename of certificate file (or its base64 representation)
Optional character for delimiter [default = semicolon “;”]
String
Subject name or Empty string if error
Use X509.QueryCert with query
"subjectName"
for more output options.
X509 Class
CryptoSysPKI Namespace
Calculate the thumbprint (message digest hash) of an X.509 certificate.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string CertThumb(
string certFile,
HashAlgorithm hashAlg)
Filename of certificate file (or its base64 representation)
HashAlgorithm
String
String containing the message digest in hexadecimal format
X509 Class
CryptoSysPKI Namespace
Check whether an X.509 certificate has been revoked in a Certificate Revocation List (CRL).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int CheckCertInCRL(
string certFile,
string crlFile,
string issuerCert,
string dateStr
)
name of X.509 certificate to be checked (or base64 representation)
name of CRL file
(optional) with name of X.509 certificate file for the entity that issued the CRL (or base64 representation)
(optional) with date in ISO format
(yyyy-mm-dd[Thh[:nn:ss]][Z]
) on or after you wish to check
for revocation. Leave empty “” for any date. The time must be in GMT
(UTC, Zulu time)
Int32
Zero if the certificate is NOT in the CRL; X509.Revoked (REVOCATION_ERROR
+42) if the certificate has been revoked; otherwise a nonzero error code.
The optional dateStr
parameter allows you check whether
a certificate was revoked only after the given date-time, which must be
GMT (UTC). If the optional issuerCert
is specified, the
signature of the CRL will be checked against the key in the issuer’s
certificate and a SIGNATURE_ERROR will result if the signature is
invalid.
X509 Class
CryptoSysPKI Namespace
VerifyCert(String, String)
CertIsValidNow(String)
Return number of certificates in a PKCS-7 “certs-only” certificate chain file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int GetCertCountInP7Chain(
string inputFile
)
Name of the PKCS-7 “certs-only” file, or a string containing its PEM textual representation.
Int32
Number of X.509 certificates found or a negative error code.
X509 Class
CryptoSysPKI Namespace
Extract an X.509 certificate from a PKCS-7 “certs-only” certificate chain file, saving the output directly as a new file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int GetCertFromP7Chain(
string outputFile,
string inputFile,
int index
)
Name of output file to be created
Name of the PKCS-7 “certs-only” file, or a string containing its PEM textual representation.
specifying which certificate (1,2,…) in the chain to extract.
Int32
If successful and index
is greater than zero, it returns
the number of bytes written to the output file, which may be zero if no
certificate could be found at the given index. If an error occurred, it
returns a negative error code.
[New in v12.2] To find the number of certificates in the chain, use
GetCertCountInP7Chain. The old
(deprecated) way to find the count of certificates was to set
index
to zero.
X509 Class
CryptoSysPKI Namespace
Extract an X.509 certificate from a PKCS-12 PFX/.p12 file, saving the output directly as a new file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int GetCertFromPFX(
string outputFile,
string inputFile,
string password = ""
)
Name of output file to be created
Name of the PKCS-12 file, or a string containing its PEM textual representation.
Password or “” if not encrypted (default=““)
Int32
If successful, it returns the number of bytes written to the output
file; otherwise it returns a negative error code
Only supports weak 40-bit RC2 encryption for the certificate.
X509 Class
CryptoSysPKI Namespace
Extract all X.509 certificates from a PKCS-12 PFX/.p12 file, saving the output directly as a new PKCS-7 “certs-only” certificate chain file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int GetP7ChainFromPFX(
string outputFile,
string inputFile,
string password
)
Name of output file to be created
Name of the PKCS-12 file, or a string containing its PEM textual representation.
Password or “” if not encrypted
Int32
If successful, it returns the number of bytes written to the output
file; otherwise it returns a negative error code
Only supports weak 40-bit RC2 encryption for the certificate.
X509 Class
CryptoSysPKI Namespace
Create a message digest of the Issuer’s name and the cert serial number.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string HashIssuerAndSN(
string certFile,
HashAlgorithm algorithm)
Filename of certificate file (or its base64 representation)
Hash algorithm to use [default = SHA-1]
String
Message digest in hex format or Empty string if error
This (should) give a unique identifier for any certificate
X509 Class
CryptoSysPKI Namespace
Returns a bitfield containing the keyUsage
flags.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int KeyUsageFlags(
string certFile
)
Filename of certificate file (or its base64 representation)
Int32
If successful, it returns a positive integer containing the
keyUsage
flags; or 0 if no keyUsage
flags are
set; otherwise it returns a negative error
code
See X509.KeyUsageOptions.
X509 Class
CryptoSysPKI Namespace
Create a new X.509 certificate using subject’s public key and issuer’s private key files with signature options.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int MakeCert(
string certFile,
string issuerCert,
string subjectPubKeyFile,
string issuerPriKeyFile,
int certNum,
int yearsValid,
string distName,
string extensions,
.KeyUsageOptions keyUsageOptions,
X509string password,
,
SigAlgorithm sigAlg.CertOptions options
X509)
Name of file to be created
Name of issuer’s certificate file
File containing subjects public key data
File containing issuer’s private key data
Issue number for new certificate
How many years to be valid
Distinguished name string. See Distinguished Names in the main manual.
Extensions: a list of attribute-value pairs separated by semicolons (;). See X.509 Extensions Parameter in the main manual.
Key usage options
For issuer’s private key, if encrypted.
Signature algorithm to sign certificate.
Option flags: set as zero for defaults.
Int32
Zero if successful or a non-zero error
code
Valid extensions are: | rfc822Name=string; | To set
the rfc822 email address in the subjectAltName
extension,
e.g. rfc822Name=myname@testorg.com
. | | ———————————— |
———————————————————————————————————————————————————————————————————————————————————–
| | serialNumber=hex-digits; | To override the serial
number set by certNum
with a larger, unlimited integer in
hexadecimal format, e.g. serialNumber=12deadbeefcafe0123
. |
| subjectKeyIdentifier=hex-digits; | To set the
subjectAltName
extension with an octet string (binary)
value specified in hex format
e.g. subjectKeyIdentifier=fedcba9876543210
. | |
notAfter=iso-date-string; | To override the validity
period set by yearsValid
with a specific date and time in
ISO format, e.g. notAfter=2020-12-31
or
notAfter=2020-12-31T14:03:59
. If no time is given it will
default to 23:59:59. Note that this time is UTC (GMT) not local. | |
notBefore=iso-date-string; | To override the default
start time from one minute ago to a specific date and time in ISO
format, e.g. notBefore=2008-12-31
. If no time is given it
will default to 00:00:01. Note that this time is UTC (GMT) not local. |
| <dotted-oid>=#<hexstring>; | Add an
arbitrary X.509 version 3 Extension with typeID
set to
decoded <dotted-oid> and extnValue
set to ASN.1 value
encoded in <hexstring>. |
As an alternative, you can create a new X.509 certificate using a
PKCS-10 certificate signing request (CSR) file. Pass the name of the CSR
file in the subjectPubkeyFile parameter and set the distName empty
""
. The empty distinguished name parameter is a flag that a
CSR file is being used.
X509 Class
CryptoSysPKI Namespace
Create a self-signed X.509 certificate with signature options.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int MakeCertSelf(
string certFile,
string privateKeyFile,
int certNum,
int yearsValid,
string distName,
string extensions,
.KeyUsageOptions keyUsageOptions,
X509string password,
,
SigAlgorithm sigAlg.CertOptions options
X509)
Name of file to be created
File containing issuer’s private key data
Issue number for new certificate
How many years to be valid
Distinguished name string. See Distinguished Names in the main manual.
Extensions: a list of attribute-value pairs separated by semicolons (;). See X.509 Extensions Parameter in the main manual.
Key usage options
For issuer’s private key
Signature algorithm to sign certificate.
Option flags: set as zero for defaults.
Int32
Zero if successful or a non-zero error
code
X509 Class
CryptoSysPKI Namespace
Create an X.509 Certificate Revocation List (CRL).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int MakeCRL(
string crlFile,
string issuerCert,
string issuerKeyFile,
string password,
string revokedCertList,
string extensions,
,
SigAlgorithm sigAlg.CrlOptions opts
X509)
name of new CRL file to be created
name of issuer’s X.509 certificate file (or base64 representation)
name of issuer’s encrypted private key file
password for Issuer’s encrypted private key file
list of revoked certificates in format
serialNumber,revocationDate; ...
or the empty string
""
for no revoked certificates. See the Remarks section
below for more details
A list of attribute-value pairs separated by semicolons (;) or the
empty string ""
. Valid attribute-value pairs are:
lastUpdate
=iso-date-stringnextUpdate
=iso-date-string
Signature algorithm.
Options
Int32
If successful, the return value is zero; otherwise it returns a non-zero
error code.
This creates a version 1 CRL file with no extensions or cRLReason’s.
The parameter revokedCertList
must be in the form
serialNumber,revocationDate;serialNumber,revocationDate; ...
.
The serialNumber must either be a positive decimal integer
(e.g. 123
) or the number in hex format preceded by #x
(e.g. #x0102deadbeef
). The revocation date must be in ISO
date format (e.g. 2009-12-31T12:59:59Z
). For example,
"1,2007-12-31; 2, 2009-12-31T12:59:59Z; 66000,2066-01-01; #x0102deadbeef,2010-02-28T01:01:59"
By default, the lastUpdate
time in the CRL is set to the
time given by the system clock, and nextUpdate
time is left
empty. You can specify your own times using the lastUpdate
and nextUpdate
attributes in the extensions parameter.
Times, if specified, must be in ISO 8601 format and are always
interpreted as GMT times whether or not you add a “Z”.
X509 Class
CryptoSysPKI Namespace
Query an X.509 certificate file for selected information.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string QueryCert(
string certFile,
string query,
.OutputOpts outOpts = X509.OutputOpts.Default
X509)
Filename of certificate file (or its base64 representation)
Query string (case insensitive)
Optional options for output (default = 0)
String
String containing the result, or an empty string if query not found or
on error.
Both binary BER and PEM-format certificates can be read, as can a base64 representation of the certificate.
Valid queries are:
"version" |
X.509 version number, e.g. "3" . |
---|---|
"serialNumber" |
Serial number in hex-encoded format. |
"signatureAlgorithm" |
Signature algorithm used,
e.g. "sha1WithRSAEncryption" . |
"signatureValue" |
Signature value in hex-encoded format. |
"notBefore" |
Date on which the certificate validity period begins in ISO format
yyyy-mm-ddThh:nn:ssZ |
"notAfter" |
Date on which the certificate validity period ends in ISO format
yyyy-mm-ddThh:nn:ssZ |
"issuerName" |
Distinguished name (DN) of entity who has signed and issued the certificate. |
"subjectName" |
Distinguished name (DN) of the subject. |
"subjectPublicKeyAlgorithm" |
Algorithm used in subject’s public key,
e.g. "dsa" . |
"subjectKeyIdentifier" |
The subject key identifier extension, if present, in hex-encoded format. |
"authorityKeyIdentifier" |
The authority key identifier extension, if present, in hex-encoded format. |
"rfc822Name" |
Internet mail address contained in a subjectAltName extension, if present. |
"isCA" |
Returns "1" if the subject type is a CA, otherwise
returns "0" . |
"keyUsageString" |
keyUsage flags in text format,
e.g. "digitalSignature,nonRepudiation" . |
"extKeyUsageString" |
extKeyUsage purposes in text format,
e.g. "codeSigning,timeStamping" . |
"cRLDistributionPointsURI" |
First URI found in cRLDistributionPoints , if any. |
"authorityInfoAccessURI" |
First URI found in authorityInfoAccess , if any. |
"subjectAltName" |
Subject alternative name extension, if present. |
"hashAlgorithm" |
Hash algorithm used in signature, e.g. "sha256" . |
"pssParams" |
Parameters used for RSA-PSS (if applicable). |
X509 Class
CryptoSysPKI Namespace
Read an X.509 certificate into a base64 string from PKCS-7 “certs-only” data.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string ReadCertStringFromP7Chain(
string inputFile,
int index
)
filename of a PKCS-7 “certs-only” file, or a string containing its PEM textual representation.
specifying which certificate (1,2,…) in the chain to extract.
String
String in continuous base64 format, or an empty string on error.
[New in v12.2] To find the number of certificates in the chain, use
GetCertCountInP7Chain. The old
(deprecated) way to find the count of certificates was to set
index
to zero.
X509 Class
CryptoSysPKI Namespace
Read an X.509 certificate into a base64 string from PKCS-12 PFX/.p12 data.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string ReadCertStringFromPFX(
string inputFile,
string password
)
filename of a PFX file, or a string containing its PEM textual representation.
password for PFX or ""
if certificate is not
encrypted
String
String in continuous base64 format, or an empty string on error.
Only supports weak 40-bit RC2 encryption for the certificate.
X509 Class
CryptoSysPKI Namespace
Create a base64 string representation of a X.509 certificate file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string ReadStringFromFile(
string certFile
)
Filename of certificate file (or its base64 representation)
String
String in continuous base64 format, or an empty string on error.
X509 Class
CryptoSysPKI Namespace
Create a new X.509 certificate file from a base64 string representation.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int SaveFileFromString(
string newCertFile,
string certString,
bool inPEMFormat
)
Name of new certificate file to be created.
String containing certificate data in base64 format.
True
to save in base64 PEM format, or false
to save in binary DER format.
Int32
Zero if successful or non-zero error
code
Any existing file of the same name will be overwritten without warning.
A PEM format file will start with
-----BEGIN CERTIFICATE-----
.
X509 Class
CryptoSysPKI Namespace
Dump details of an X.509 certificate or a X.509 certificate revocation list (CRL) or a PKCS-10 certificate signing request (CSR) to a text file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int TextDump(
string outputFile,
string certFile,
.OutputOpts outOpts = X509.OutputOpts.Default
X509)
Filename of text file to be created
Filename of certificate file (or its base64 representation)
Options for output (optional)
Int32
If successful, the return value is zero; otherwise it returns a nonzero
error code.
The notation [!]
denotes a critical extension,
e.g. Key Usage[!]:
.
X509 Class
CryptoSysPKI Namespace
Dump details of an X.509 certificate or a X.509 certificate revocation list (CRL) or a PKCS-10 certificate signing request (CSR) to a string.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static string TextDumpToString(
string certFile,
.OutputOpts outOpts = X509.OutputOpts.Default
X509)
Filename of certificate file (or its base64 representation)
Options for output
String
String containing the result, or an empty string on error.
The notation [!]
denotes a critical extension,
e.g. Key Usage[!]:
.
X509 Class
CryptoSysPKI Namespace
Validate a certificate path.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int ValidatePath(
string certListOrP7File,
string trustedCert = "",
bool noTimeCheck = false
)
either a list of certificate names separated by a semicolon or the name of a PKCS-7 “certs-only” file containing the certificates to be validated
(optional) name of the trusted certificate (or base64 representation)
Set True to avoid checking if the certificates are valid now [default = check validity dates against system clock].
Int32
Zero if the certification path is valid; X509.Invalid (CERT_PATH_ERROR
+43)
if the path is invalid; otherwise a negative error code.
X509 Class
CryptoSysPKI Namespace
Verify that an X.509 certificate has been signed by its issuer.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static int VerifyCert(
string certToVerify,
string issuerCert
)
Filename of certificate to verify
Filename of purported issuer’s certificate
Int32
Zero if the certificate’s signature is valid; X509.Failure (SIGNATURE_ERROR
+22)
if the validation fails; otherwise a positive error code.
This can also be used to verify that an X.509 Certificate Revocation
List (CRL) or PKCS#10 Certification Signing Request (CSR) has been
signed by the owner of the issuer’s certificate. Just pass the name of
the file (or its base64/PEM string form) as
certToVerify
.
X509 Class
CryptoSysPKI Namespace
Return value from X509.CertIsValidNow indicating that the
certificate has expired (EXPIRED_ERROR
).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public const int Expired = 16
Int32
X509 Class
CryptoSysPKI Namespace
Return value from X509.VerifyCert
indicating failure (SIGNATURE_ERROR
).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public const int Failure = 22
Int32
X509 Class
CryptoSysPKI Namespace
Return value from X509.ValidatePath
indicating that the certificate path is invalid
(CERT_PATH_ERROR
).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public const int Invalid = 43
Int32
X509 Class
CryptoSysPKI Namespace
Return value from X509.CheckCertInCRL indicating that the
certificate is revoked (REVOCATION_ERROR
).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public const int Revoked = 42
Int32
X509 Class
CryptoSysPKI Namespace
Extendable-output function (XOF) methods.
System.Object
CryptoSysPKI.Xof
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public class Xof
The Xof type exposes the following members.
Name | Description |
---|---|
Bytes | Generate bytes using an eXtendable-Output Function (XOF). |
Generate bytes using an eXtendable-Output Function (XOF).
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public static byte[] Bytes(
int numBytes,
byte[] message,
.Alg xofAlg
Xof)
Required number of output bytes.
Input message data.
XOF algorithm.
Byte[]
Output data in byte array.
// Ref: "SHA-3 XOF Test Vectors for Byte-Oriented Output"
// File `SHAKE256VariableOut.rsp` COUNT = 1244
byte[] msg = "6ae23f058f0f2264a18cd609acc26dd4dbc00f5c3ee9e13ecaea2bb5a2f0bb6b".FromHex();
int nbytes = 2000 / 8; // 2000 bits == 250 bytes
byte[] b = Xof.Bytes(nbytes, msg, Xof.Alg.Shake256);
.WriteLine(b.ToHex());
Console/*
B9B92544FB25CFE4EC6FE437D8DA2BBE
00F7BDAFACE3DE97B8775A44D753C3AD
CA3F7C6F183CC8647E229070439AA953
9AE1F8F13470C9D3527FFFDEEF6C94F9
F0520FF0C1BA8B16E16014E1AF43AC6D
94CB7929188CCE9D7B02F81A2746F52B
A16988E5F6D93298D778DFE05EA0EF25
6AE3728643CE3E29C794A0370E9CA6A8
BF3E7A41E86770676AC106F7AE79E670
27CE7B7B38EFE27D253A52B5CB54D6EB
4367A87736ED48CB45EF27F42683DA14
0ED3295DFC575D3EA38CFC2A3697CC92
864305407369B4ABAC054E497378DD9F
D0C4B352EA3185CE1178B3DC1599DF69
DB29259D4735320C8E7D33E8226620C9
A1D22761F1D35BDFF79A*/
// Using MGF1-SHA-256. From SPHINCS+ test vectors r.3
int nbytes = 34;
byte[] msg = "3b5c056af3ebba70d4c805380420585562b32410a778f558ff951252407647e3".FromHex();
byte[] b = Xof.Bytes(nbytes, msg, Xof.Alg.Mgf1_Sha256);
.WriteLine(b.ToHex());
Console// 5B7EB772AECF04C74AF07D9D9C1C1F8D3A90DCDA00D5BAB1DC28DAECDC86EB87611
Xof Class
CryptoSysPKI Namespace
Authenticated encryption algorithm.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum AeadAlgorithm
Member name | Description |
---|---|
Aes_128_Gcm | Use the AEAD_AES_128_GCM authenticated encryption algorithm from RFC 5116. |
Aes_192_Gcm | Use the AES-192-GCM authenticated encryption algorithm in the same manner as RFC 5116. |
Aes_256_Gcm | Use the AEAD_AES_256_GCM authenticated encryption algorithm from RFC 5116. |
ChaCha20_Poly1305 | Use the AEAD_CHACHA20_POLY1305 authenticated encryption algorithm from RFC 8439. |
Options for ASN.1 methods
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[FlagsAttribute]
public enum Options
Member name | Description |
---|---|
Default | Default options |
NoComments | Hide the comments [default=show comments] |
AddLevels | Show level numbers [default=hide level numbers] |
Advanced options
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[FlagsAttribute]
public enum Opts
Member name | Description |
---|---|
Default | Default options |
PrefixIV | Prefix (prepend) the IV before the ciphertext in the output (ignored for ECB mode) |
Block Cipher Algorithm
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum CipherAlgorithm
Member name | Description |
---|---|
Tdea | Triple DES (TDEA, 3DES, des-ede3) |
Aes128 | AES-128 |
Aes192 | AES-192 |
Aes256 | AES-256 |
Advanced options for CMS compressed-data objects
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[FlagsAttribute]
public enum ComprDataOptions
Member name | Description |
---|---|
Default | Default options. |
NoInflate | Extract the compressed data as is without inflation. |
Content encryption algorithm.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum ContentEncrAlg
Member name | Description |
---|---|
Default | Default = AES-128 CHANGED in [v23.0] |
Tdea | Triple DES (TDEA, 3DES, des-ede3) |
Aes128 | AES-128 (default) |
Aes192 | AES-192 |
Aes256 | AES-256 |
Aes_128_Gcm | AES-128-GCM authenticated encryption algorithm from RFC5116. |
Aes_192_Gcm | AES-192-GCM authenticated encryption algorithm in the same manner as RFC5116. |
Aes_256_Gcm | AES-256-GCM authenticated encryption algorithm from RFC5116. |
ChaCha20_Poly1305 | AEAD_CHACHA20_POLY1305 authenticated encryption algorithm from RFC8439. |
New in [v22.0]. Supersedes CipherAlgorithm parameter. NOTE Default algorithm is now AES-128 (changed in [v23.0])
Advanced options for CMS enveloped-data objects.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[FlagsAttribute]
public enum EnvDataOptions
Member name | Description |
---|---|
None | Default options. |
Authenticated | Obsolete. Use AES-GCM authenticated encryption instead of AES-CBC (redundant as of [v22.0]). |
FormatBase64 | Encode output in base64 (default = binary). |
Mgf1Sha1 | Force the MGF1 hash function to be SHA-1 (RSA-OAEP only, default = same as encoding hash function). |
UseSki | Use subjectKeyIdentifier (SKI) instead of issuerAndSerialNumber for RecipientIdentifier. |
AltAlgId | Use alternative (non-standard) alternative TeleTrusT Content Encryption Algorithm Identifier. |
BigFile | Use to speed up the encryption of large files (binary file to binary file only). |
Output format.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum Format
Member name | Description |
---|---|
Default | Default output format |
Binary | Binary output (default) |
FormatBase64 | Output is encoded in base64 (default = binary). |
Key encryption algorithm.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum KeyEncrAlgorithm
Member name | Description |
---|---|
Default | Default |
Rsa_Pkcs1v1_5 | RSAES-PKCS-v1_5 (rsaEncryption ) |
Rsa_Kem | Encrypt the key using the RSA Key Encapsulation Mechanism (RSA-KEM) algorithm |
Rsa_Oaep | RSAES-OAEP |
Options for reading CMS objects.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[FlagsAttribute]
public enum ReadOptions
Member name | Description |
---|---|
None | Default options. |
BigFile | Use to speed up the encryption of large files (binary file input only). |
Signature algorithm for CMS signed-data objects.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum SigAlg
Member name | Description |
---|---|
Default | Use default signature algorithm (rsa-sha1/sha1WithRSAEncryption) |
Rsa_Sha1 | Use sha1WithRSAEncryption (rsa-sha1) signature algorithm [default] |
Rsa_Md5 | Use md5WithRSAEncryption (rsa-md5) signature algorithm [legacy, not recommended] |
Rsa_Sha256 | Use sha256WithRSAEncryption (rsa-sha256) signature algorithm |
Rsa_Sha384 | Use sha384WithRSAEncryption (rsa-sha384) signature algorithm |
Rsa_Sha512 | Use sha512WithRSAEncryption (rsa-sha512) signature algorithm |
Rsa_Sha224 | Use sha224WithRSAEncryption (rsa-sha224) signature algorithm |
Ecdsa_Sha1 | Use ecdsaWithSHA1 (ecdsa-sha1) signature algorithm |
Ecdsa_Sha224 | Use ecdsaWithSHA224 (ecdsa-sha224) signature algorithm |
Ecdsa_Sha256 | Use ecdsaWithSHA256 (ecdsa-sha256) signature algorithm |
Ecdsa_Sha384 | Use ecdsaWithSHA384 (ecdsa-sha384) signature algorithm |
Ecdsa_Sha512 | Use ecdsaWithSHA512 (ecdsa-sha512) signature algorithm |
Rsa_Pss_Sha1 | Use RSA-PSS signature algorithm with SHA-1 |
Rsa_Pss_Sha256 | Use RSA-PSS signature algorithm with SHA-256 |
Rsa_Pss_Sha384 | Use RSA-PSS signature algorithm with SHA-384 |
Rsa_Pss_Sha512 | Use RSA-PSS signature algorithm with SHA-512 |
Rsa_Pss_Sha224 | Use RSA-PSS signature algorithm with SHA-224 |
Ed25519 | Use Ed25519 signature algorithm [RFC8032] |
Ed448 | Use Ed448 signature algorithm [RFC8032 |
Advanced options for CMS signed-data objects
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[FlagsAttribute]
public enum SigDataOptions
Member name | Description |
---|---|
Default | Default option |
ExcludeCerts | Exclude X.509 certs from output. |
ExcludeData | Exclude data from output. |
CertsOnly | Create a “certs-only” PKCS#7 certficate chain. |
IncludeAttributes | To add signed attributes (default = no signed attributes) including content-type and message-digest plus any more added below. |
AddSignTime | Add signing time to the signed attributes (requires IncludeAttributes). |
AddSmimeCapabilities | Add S/MIME capabilities to the signed attributes (requires IncludeAttributes). |
AddSigningCertificate | Add an ESS Signing Certificate attribute to the signed attributes (requires IncludeAttributes). |
AddAlgProtection | Add an Algorithm Protection Attribute [RFC6211] to the signed attributes (requires IncludeAttributes). |
FormatBase64 | Create output/expect input in base64 format (default = binary). |
AddSigner | Add a new signer to an existing SignedData object. |
PseudoSig | Create/sign a “pseudo” SignedData object with dummy placeholder signature. |
Pss_SaltLenZero | Use a zero-length salt in an RSA-PSS signature (default =
hLen the length of the digest output). |
Mgf1Sha1 | Force the MGF1 hash function to be SHA-1 (RSASSA-PSS only, default = same as encoding hash function). |
UseSki | Use subjectKeyIdentifier (SKI) instead of issuerAndSerialNumber for SignerIdentifier. |
NoOuter | Create a “naked” SignedData object with no outerContentInfo as permitted by PKCS#7 v1.6 (specialist option). |
AltAlgId | Use alternative (non-standard) signature algorithm identifiers, e.g. ‘sha1withRSAEncryption’ instead of ‘rsaEncryption’. |
BigFile | Use to speed up the processing of large files. |
Conversion directions for ByteEncoding.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum EncodingConversion
Member name | Description |
---|---|
Utf8_From_Latin1 | Converts UTF-8-encoded bytes into Latin-1-encoded |
Latin1_From_Utf8 | Converts Latin-1-encoded bytes into UTF-8-encoded |
Byte order.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum EndianNess
Member name | Description |
---|---|
BigEndian | Most-significant byte first |
LittleEndian | Least-significant byte first |
Supported curve names.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum CurveName
Member name | Description |
---|---|
Secp192r1 | NIST curve P-192 |
Secp224r1 | NIST curve P-224 |
Secp256r1 | NIST curve P-256 |
Secp384r1 | NIST curve P-384 |
Secp521r1 | NIST curve P-521 |
Secp256k1 | “Bitcoin” curve |
P_192 | NIST curve P-192 (synonym for secp192r1 ) |
P_224 | NIST curve P-256 (synonym for secp256r1 ) |
P_256 | NIST curve P-224 (synonym for secp224r1 ) |
P_384 | NIST curve P-384 (synonym for secp384r1 ) |
P_521 | NIST curve P-521 (synonym for secp521r1 ) |
Prime192v1 | Alternative name for NIST curve P-192 |
Prime256v1 | Alternative name for NIST curve P-256 |
BrainpoolP256r1 | ECC Brainpool curve [RFC5639] |
BrainpoolP384r1 | ECC Brainpool curve [RFC5639] |
BrainpoolP512r1 | ECC Brainpool curve [RFC5639] |
Ed25519 | Safe curve for EdDSA |
Ed448 | Safe curve for EdDSA |
X25519 | Safe curve for ECDH |
X448 | Safe curve for ECDH |
Format for output files.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum Format
Member name | Description |
---|---|
Default | Default = binary |
Binary | Binary DER-encoded |
PEM | PEM-encoded text file |
Key type for unencrypted key file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum KeyType
Member name | Description |
---|---|
Default | Save key in the default format. |
PrivateKey | Key value represents a private key (use for reading safe curves) |
PublicKey | Key value represents a public key (use for reading safe curves) |
Pkcs8PrivateKeyInfo | Save a NIST/SEC curve private key in PKCS#8
PrivateKeyInfo format (ignored for a public key) |
Legacy | Save a safe private key in “legacy” PKCS#8 v1 format (default is v2 OneAsymmetricKey) |
Password-based encryption scheme to encrypt the private key file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum PbeScheme
Member name | Description |
---|---|
Default | Default option (pbeWithSHAAnd3-KeyTripleDES-CBC) |
PbeWithSHAAnd_KeyTripleDES_CBC | pbeWithSHAAnd3-KeyTripleDES-CBC from PKCS#12 |
Pbe_Pbkdf2_des_EDE3_CBC | “pkcs5PBES2” with key derivation function “pkcs5PBKDF2” and encryption scheme “des-EDE3-CBC” |
Pbe_Pbkdf2_aes128_CBC | “pkcs5PBES2” with key derivation function “pkcs5PBKDF2” and encryption scheme “aes128-CBC” |
Pbe_Pbkdf2_aes192_CBC | “pkcs5PBES2” with key derivation function “pkcs5PBKDF2” and encryption scheme “aes192-CBC” |
Pbe_Pbkdf2_aes256_CBC | “pkcs5PBES2” with key derivation function “pkcs5PBKDF2” and encryption scheme “aes256-CBC” |
Base for encoding methods
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum EncodingBase
Member name | Description |
---|---|
Base64 | Base64 encoding |
Base16 | Base16 encoding (i.e. hexadecimal) |
Message Digest Hash Algorithm
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum HashAlgorithm
Member name | Description |
---|---|
Sha1 | SHA-1 (as per FIPS PUB 180-4) |
Md5 | MD5 (as per RFC 1321) [legacy, not recommended] |
Md2 | MD2 (as per RFC 1319) [legacy, definitely not recommended] |
Sha256 | SHA-256 (as per FIPS PUB 180-4) |
Sha384 | SHA-384 (as per FIPS PUB 180-4) |
Sha512 | SHA-512 (as per FIPS PUB 180-4) |
Sha224 | SHA-224 (as per FIPS PUB 180-4) |
Ripemd160 | RIPEMD-160 |
Bitcoin160 | RIPEMD-160 hash of a SHA-256 hash
(RIPEMD160(SHA256(m)) ) |
Sha3_224 | SHA-3-224 (as per FIPS PUB 202) |
Sha3_256 | SHA-3-256 (as per FIPS PUB 202) |
Sha3_384 | SHA-3-384 (as per FIPS PUB 202) |
Sha3_512 | SHA-3-256 (as per FIPS PUB 202) |
AEAD functions supported for HPKE
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum AeadAlg
Member name | Description |
---|---|
None | No AEAD algorithm. |
Aes_128_Gcm | Use the AEAD_AES_128_GCM authenticated encryption algorithm from RFC5116. |
Aes_256_Gcm | Use the AEAD_AES_256_GCM authenticated encryption algorithm from RFC5116. |
ChaCha20_Poly1305 | Use the AEAD_CHACHA20_POLY1305 authenticated encryption algorithm from RFC8439. |
Supported ECDH curves for HPKE
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum CurveName
Member name | Description |
---|---|
P_256 | NIST curve P-256 |
P_384 | NIST curve P-384 |
P_521 | NIST curve P-521 |
X25519 | ECDH curve X25519 from RFC7748 |
X448 | ECDH curve X448 from RFC7748 |
Options to format or re-encode output.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum OutputOpts
Member name | Description |
---|---|
Default | Default = output as ephemeral “internal” key string. |
KeyAsHex | Output key in hex format compatible with test vectors in [RFC9180] |
Hash algorithms for KDF
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum HashAlg
Member name | Description |
---|---|
Sha1 | SHA-1 (as per FIPS PUB 180-4) |
Sha256 | SHA-256 (as per FIPS PUB 180-4) |
Sha384 | SHA-384 (as per FIPS PUB 180-4) |
Sha512 | SHA-512 (as per FIPS PUB 180-4) |
Sha224 | SHA-224 (as per FIPS PUB 180-4) |
Key derivation functions
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum KdfAlg
Member name | Description |
---|---|
X963 | ANSI-X9.63-KDF key derivation function (default) |
Hkdf | HMAC-based Key Derivation Function (HKDF) from [RFC5869] |
Kdf2 | KDF2 from ANSI-X9.44 |
Kdf3 | KDF3 from ANSI-X9.44 |
Key wrap algorithms for KDF
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum KeyWrapAlg
Member name | Description |
---|---|
Default | Default for Cms.MakeEnvData only. |
Cms3DESwrap | Triple-DES Key Wrap algorithm from [RFC3217] |
Aes128_wrap | AES-128 key wrap from [RFC3394] |
Aes192_wrap | AES-192 key wrap from [RFC3394] |
Aes256_wrap | AES-256 key wrap from [RFC3394] |
Cipher Mode
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum Mode
Member name | Description |
---|---|
ECB | Electronic Code Book mode |
CBC | Cipher Block Chaining mode |
OFB | Output Feedback mode |
CFB | Cipher Feedback mode |
CTR | Counter mode |
GCM | Galois/Counter mode (AES only) |
Block Cipher Padding
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum Padding
Member name | Description |
---|---|
Default | Use default padding |
NoPad | No padding is added |
Pkcs5 | The padding scheme described in PKCS#5/#7 |
OneAndZeroes | Pad with 0x80 followed by as many zero bytes necessary to fill the block |
AnsiX923 | The padding scheme described in ANSI X9.23 |
W3CPadding | The padding scheme described in W3C https://www.w3.org/TR/xmlenc-core1/#sec-Padding |
Specialist options.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[FlagsAttribute]
public enum Options
Member name | Description |
---|---|
Default | Default options: re-encrypt private key with “TripleDES-SHA1”, encrypt certificate with 40-bit RC2, output in DER binary form. |
Aes256_Sha256 | Override other encryption options and encrypt both the private key and certificate using “AES256-SHA256” |
FormatPem | Create the output file in PEM format (default is DER-encoded binary). |
AltFormat | Create a PFX file with the exact peculiarities used by Microsoft (default is OpenSSL). |
StrongCert | Encrypt the certificate with “stronger” TripleDES-SHA1 (default is “weak” 40-bit RC2). |
PlainCert | Store the certificate in unencrypted form (default is encrypted with 40-bit RC2). |
CloneKey | Store the private key in the exact form of the pkcs-8 input file (default is to re-encrypt with Triple DES). |
DoubleEncrypt | Double-encrypt the private key (specialist option). |
Pseudorandom function (PRF) algorithm.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum Alg
Member name | Description |
---|---|
Kmac128 | KMAC128 as per NIST SP 800-185 |
Kmac256 | KMAC256 as per NIST SP 800-185 |
Rng options
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum Options
Member name | Description |
---|---|
Default | Default option |
NoIntelDrng | Turn off support for INTEL(R) DRNG for the current session. |
Required security strength for user-prompted entropy
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum Strength
Member name | Description |
---|---|
Default | Default option |
Bits_112 | 112 bits of security (default) |
Bits_128 | 128 bits of security |
Bits_192 | 192 bits of security |
Bits_256 | 256 bits of security |
Advanced options.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[FlagsAttribute]
public enum AdvOptions
Member name | Description |
---|---|
Default | Default options. |
Mgf1_Sha1 | Force the MGF hash function to be SHA-1 (OAEP only, default = same as encoding set by Rsa.HashAlg) |
Encoding method for encryption.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum EME
Member name | Description |
---|---|
PKCSv1_5 | EME-PKCS1-v1_5 encoding method |
OAEP | EME-OAEP encoding method |
See PKCS#1 v2.2 [RFC8017]
Format for saved RSA key.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum Format
Member name | Description |
---|---|
Default | Default = Binary |
Binary | Binary DER-encoded |
PEM | PEM Format |
SSL | PEM format compatible with OpenSSL |
Hash function for OAEP encoding.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum HashAlg
Member name | Description |
---|---|
Sha1 | SHA-1 (default) |
Sha256 | SHA-256 |
Sha384 | SHA-384 |
Sha512 | SHA-512 |
Sha224 | SHA-224 |
Password-based encryption scheme to be used to encrypt the private key file.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum PbeOptions
Member name | Description |
---|---|
Default | Default option (pbeWithSHAAnd3-KeyTripleDES-CBC) |
PbeWithSHAAnd_KeyTripleDES_CBC | pbeWithSHAAnd3-KeyTripleDES-CBC from PKCS#12 |
Pbe_Pbkdf2_des_EDE3_CBC | “pkcs5PBES2” with key derivation function “pkcs5PBKDF2” and encryption scheme “des-EDE3-CBC” |
Pkcs5PBES2_des_EDE3_CBC | “pkcs5PBES2” with “pkcs5PBKDF2” and “des-EDE3-CBC” [Synonym retained for backwards compatibility] |
Pbe_Pbkdf2_aes128_CBC | “pkcs5PBES2” with key derivation function “pkcs5PBKDF2” and encryption scheme “aes128-CBC” |
Pbe_Pbkdf2_aes192_CBC | “pkcs5PBES2” with key derivation function “pkcs5PBKDF2” and encryption scheme “aes192-CBC” |
Pbe_Pbkdf2_aes256_CBC | “pkcs5PBES2” with key derivation function “pkcs5PBKDF2” and encryption scheme “aes256-CBC” |
PbeWithMD5AndDES_CBC | pbeWithMD5AndDES-CBC [legacy, not recommended for new implementations] |
PbeWithMD2AndDES_CBC | pbeWithMD2AndDES-CBC [legacy, not recommended for new implementations] |
PbeWithSHA1AndDES_CBC | pbeWithSHA1AndDES-CBC [legacy, not recommended for new implementations] |
Choices for public exponent (e)
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum PublicExponent
Member name | Description |
---|---|
Exp_EQ_3 | Set exponent equal to 3 (F0) |
Exp_EQ_5 | Set exponent equal to 5 (F1) |
Exp_EQ_17 | Set exponent equal to 17 (F2) |
Exp_EQ_257 | Set exponent equal to 257 (F3) |
Exp_EQ_65537 | Set exponent equal to 65537 (F4) |
Fermat Number F(x) = 2(2x) + 1. F0 to F4 are prime.
Options when converting between internal RSA key and XML.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[FlagsAttribute]
public enum XmlOptions
Member name | Description |
---|---|
ForceRSAKeyValue | Create XML in .NET-compatible RSAKeyValue format (ToXML only) |
ExcludePrivateParams | Exclude private key parameters |
RequirePrivate | Require private key to exist in the XML input or fail (FromXML only) |
HexBinaryFormat | Create XML in non-standard hex format (ToXML only) |
Encodings for signature output.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum Encoding
Member name | Description |
---|---|
Default | Default encoding (base64) |
Base64 | Base64 encoding (default) |
Base16 | Base16 encoding (i.e. hexadecimal) |
Base64url | URL-safe base64 encoding as in section 5 of [RFC4648] |
Specialist options for signatures.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[FlagsAttribute]
public enum SigOptions
Member name | Description |
---|---|
Default | Use default options for signature. |
PssSaltLenHlen | RSA-PSS only: Set the salt length to hLen , the length
of the output of the hash function [default]. |
UseDeterministic | ECDSA only: Use the deterministic digital signature generation procedure of [RFC6979] for ECDSA signature [default=random k]. |
Asn1DERStructure | ECDSA only: Form ECDSA signature value as a DER-encoded ASN.1
structure [default=r||s ]. |
PssSaltLenMax | RSA-PSS only: Set the salt length to the maximum possible (like OpenSSL). |
PssSaltLen20 | RSA-PSS only: Set the salt length to be exactly 20 bytes regardless of the hash algorithm. |
PssSaltLenZero | RSA-PSS only: Set the salt length to be zero. |
Mgf1Sha1 | RSA-PSS only: Force the MGF hash function to be SHA-1 [default = same as signature hash algorithm] |
Specialist options for verifying a signature.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[FlagsAttribute]
public enum VerifyOpts
Member name | Description |
---|---|
Default | Use default options. |
Mgf1Sha1 | RSA-PSS only: Force the MGF hash function to be SHA-1 [default = same as signature hash algorithm] |
Signature algorithm
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum SigAlgorithm
Member name | Description |
---|---|
Default | Use default signature algorithm [rsa-sha1/sha1WithRSAEncryption] |
Rsa_Sha1 | Use sha1WithRSAEncryption (rsa-sha1) signature algorithm [default] |
Rsa_Md5 | Use md5WithRSAEncryption (rsa-md5) signature algorithm [legacy, not recommended] |
Rsa_Sha256 | Use sha256WithRSAEncryption (rsa-sha256) signature algorithm |
Rsa_Sha384 | Use sha384WithRSAEncryption (rsa-sha384) signature algorithm |
Rsa_Sha512 | Use sha512WithRSAEncryption (rsa-sha512) signature algorithm |
Rsa_Sha224 | Use sha224WithRSAEncryption (rsa-sha224) signature algorithm |
Ecdsa_Sha1 | Use ecdsaWithSHA1 (ecdsa-sha1) signature algorithm |
Ecdsa_Sha224 | Use ecdsaWithSHA224 (ecdsa-sha224) signature algorithm |
Ecdsa_Sha256 | Use ecdsaWithSHA256 (ecdsa-sha256) signature algorithm |
Ecdsa_Sha384 | Use ecdsaWithSHA384 (ecdsa-sha384) signature algorithm |
Ecdsa_Sha512 | Use ecdsaWithSHA512 (ecdsa-sha512) signature algorithm |
Rsa_Pss_Sha1 | Use RSA-PSS signature algorithm with SHA-1 |
Rsa_Pss_Sha256 | Use RSA-PSS signature algorithm with SHA-256 |
Rsa_Pss_Sha384 | Use RSA-PSS signature algorithm with SHA-384 |
Rsa_Pss_Sha512 | Use RSA-PSS signature algorithm with SHA-512 |
Rsa_Pss_Sha224 | Use RSA-PSS signature algorithm with SHA-224 |
Ed25519 | Use Ed25519 signature algorithm |
Ed448 | Use Ed448 signature algorithm |
Options for S/MIME methods
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[FlagsAttribute]
public enum Options
Member name | Description |
---|---|
Default | Default options |
EncodeBase64 | Encode output in base64 |
EncodeBinary | Encode body in binary encoding |
AddX | Add an “x-” to the content subtype (for compatibility with legacy applications) |
Wipe options.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum Options
Member name | Description |
---|---|
Default | Default options (DOD 7-pass) |
Dod7Pass | DOD 7-pass (default) |
Simple | Overwrite with single pass of zero bytes (quicker but less secure). |
Options to create X.509 certificate.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[FlagsAttribute]
public enum CertOptions
Member name | Description |
---|---|
Default | Default options |
Ecdsa_Deterministic | Use the deterministic digital signature generation procedure of [RFC6979] for an ECDSA signature. |
FormatPem | Create in PEM-encoded text file [default = binary DER-encoded] |
Pss_SaltLenZero | Use a zero-length salt in an RSA-PSS signature [default =
hLen the length of the digest output] |
UTF8String | Encode distinguished name as UTF8String [default = PrintableString] |
AuthKeyId | Add the issuer’s KeyIdentifier, if present, as an AuthorityKeyIdentifer [default = do not add] |
NoBasicConstraints | Disable the BasicConstraints extension [default = include] |
SetAsCA | Set the BasicConstraints subject type to be a CA [default = End Entity] |
VersionOne | Create a Version 1 certificate, i.e. no extensions [default = Version 3] |
Options to create Certificate Revocation List (CRL)
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[FlagsAttribute]
public enum CrlOptions
Member name | Description |
---|---|
Default | Default options |
Ecdsa_Deterministic | Use the deterministic digital signature generation procedure of [RFC6979] for an ECDSA signature. |
FormatPem | Create in PEM-encoded text file [default = binary DER-encoded] |
Pss_SaltLenZero | Use a zero-length salt in an RSA-PSS signature [default =
hLen the length of the digest output] |
Options to create PKCS#10 certificate signing request (CSR)
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[FlagsAttribute]
public enum CsrOptions
Member name | Description |
---|---|
Default | Default options |
Ecdsa_Deterministic | Use the deterministic digital signature generation procedure of [RFC6979] for an ECDSA signature. |
FormatBinary | Create in binary format [default = PEM-encoded text file] |
RequestKludge | Create a request with the “kludge” that omits the strictly mandatory attributes completely [default = include attributes with zero-length field] |
Pss_SaltLenZero | Use a zero-length salt in an RSA-PSS signature [default =
hLen the length of the digest output] |
UTF8String | Encode distinguished name as UTF8String [default = PrintableString] |
Options for key usage in certificate
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[FlagsAttribute]
public enum KeyUsageOptions
Member name | Description |
---|---|
None | Key usage extension is not included. |
DigitalSignature | subject public key is used for verifying digital signatures. |
NonRepudiation | subject public key is used to verify digital signatures used to provide a non-repudiation service. |
KeyEncipherment | subject public key is used for enciphering private or secret keys, i.e., for key transport. |
DataEncipherment | subject public key is used for directly enciphering raw user data (uncommon). |
KeyAgreement | subject public key is used for key agreement. |
KeyCertSign | subject public key is used for verifying signatures on public key certificates. |
CrlSign | subject public key is used for verifying signatures on certificate revocation lists. |
EncipherOnly | subject public key may be used only for enciphering data while performing key agreement (only if keyAgreement bit is also set). |
DecipherOnly | subject public key may be used only for deciphering data while performing key agreement (only if keyAgreement bit is also set). |
Reference: [RFC5280] s4.2.1.3 Key Usage
Options to format or re-encode output.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
[FlagsAttribute]
public enum OutputOpts
Member name | Description |
---|---|
Default | Default options |
Ldap | Output distinguished name in LDAP string representation. |
Decimal | Output serial number in decimal format [default = hex]. |
Latin1 | Encode distinguished name in Latin-1 encoding, if possible. |
Unicode | Output distinguished name in Unicode character set (UTF-8 or UTF-16 as appropriate). |
eXtendable-Output Function (XOF) algorithm.
Namespace: CryptoSysPKI
Assembly: diCrSysPKINet (in diCrSysPKINet.dll) Version:
23.0.0.36009 (23.0.0.0)
public enum Alg
Member name | Description |
---|---|
Shake128 | SHAKE128 (as per FIPS PUB 202) |
Shake256 | SHAKE256 (as per FIPS PUB 202) |
Mgf1_Sha1 | MGF1-SHA-1 (as per PKCS#1) |
Mgf1_Sha256 | MGF1-SHA-256 (as per PKCS#1) |
Mgf1_Sha512 | MGF1-SHA-512 (as per PKCS#1) |
Created: 2025-10-20 20:04:01
Copyright (C) 2025 D.I. Management Services Pty Ltd t/a CryptoSys https://cryptosys.net