Class BcTlsCrypto
public class BcTlsCrypto : AbstractTlsCrypto, TlsCrypto
- Inheritance
-
BcTlsCrypto
- Implements
- Inherited Members
Constructors
BcTlsCrypto()
public BcTlsCrypto()
BcTlsCrypto(SecureRandom)
public BcTlsCrypto(SecureRandom entropySource)
Parameters
entropySourceSecureRandom
Properties
SecureRandom
Return the primary (safest) SecureRandom for this crypto.
public override SecureRandom SecureRandom { get; }
Property Value
- SecureRandom
a SecureRandom suitable for key generation.
Methods
CloneDigest(int, IDigest)
public virtual IDigest CloneDigest(int cryptoHashAlgorithm, IDigest digest)
Parameters
Returns
CreateAeadCipher_Aes_Ccm()
protected virtual CcmBlockCipher CreateAeadCipher_Aes_Ccm()
Returns
CreateAeadCipher_Aes_Gcm()
protected virtual IAeadCipher CreateAeadCipher_Aes_Gcm()
Returns
CreateAeadCipher_Aria_Gcm()
protected virtual IAeadCipher CreateAeadCipher_Aria_Gcm()
Returns
CreateAeadCipher_Camellia_Gcm()
protected virtual IAeadCipher CreateAeadCipher_Camellia_Gcm()
Returns
CreateAeadCipher_SM4_Ccm()
protected virtual CcmBlockCipher CreateAeadCipher_SM4_Ccm()
Returns
CreateAeadCipher_SM4_Gcm()
protected virtual IAeadCipher CreateAeadCipher_SM4_Gcm()
Returns
CreateAesEngine()
protected virtual IBlockCipher CreateAesEngine()
Returns
CreateAriaEngine()
protected virtual IBlockCipher CreateAriaEngine()
Returns
CreateBlockCipher(int)
protected virtual IBlockCipher CreateBlockCipher(int encryptionAlgorithm)
Parameters
encryptionAlgorithmint
Returns
CreateCamelliaEngine()
protected virtual IBlockCipher CreateCamelliaEngine()
Returns
CreateCbcBlockCipher(IBlockCipher)
protected virtual IBlockCipher CreateCbcBlockCipher(IBlockCipher blockCipher)
Parameters
blockCipherIBlockCipher
Returns
CreateCbcBlockCipher(int)
protected virtual IBlockCipher CreateCbcBlockCipher(int encryptionAlgorithm)
Parameters
encryptionAlgorithmint
Returns
CreateCcmMode(IBlockCipher)
protected virtual CcmBlockCipher CreateCcmMode(IBlockCipher engine)
Parameters
engineIBlockCipher
Returns
CreateCertificate(short, byte[])
Create a TlsCertificate from an ASN.1 binary encoding of a certificate.
public override TlsCertificate CreateCertificate(short type, byte[] encoding)
Parameters
typeshortCertificate type as per IANA TLS Certificate Types registry.
encodingbyte[]DER/BER encoding of the certificate of interest.
Returns
- TlsCertificate
a TlsCertificate.
Exceptions
- IOException
if there is an issue on decoding or constructing the certificate.
CreateChaCha20Poly1305(TlsCryptoParameters)
protected virtual TlsCipher CreateChaCha20Poly1305(TlsCryptoParameters cryptoParams)
Parameters
cryptoParamsTlsCryptoParameters
Returns
CreateCipher(TlsCryptoParameters, int, int)
Create a cipher for the specified encryption and MAC algorithms.
public override TlsCipher CreateCipher(TlsCryptoParameters cryptoParams, int encryptionAlgorithm, int macAlgorithm)
Parameters
cryptoParamsTlsCryptoParameterscontext specific parameters.
encryptionAlgorithmintthe encryption algorithm to be employed by the cipher.
macAlgorithmintthe MAC algorithm to be employed by the cipher.
Returns
Remarks
See enumeration classes EncryptionAlgorithm, MacAlgorithm for appropriate argument values.
Exceptions
CreateCipher_Aes_Ccm(TlsCryptoParameters, int, int)
protected virtual TlsAeadCipher CreateCipher_Aes_Ccm(TlsCryptoParameters cryptoParams, int cipherKeySize, int macSize)
Parameters
cryptoParamsTlsCryptoParameterscipherKeySizeintmacSizeint
Returns
CreateCipher_Aes_Gcm(TlsCryptoParameters, int, int)
protected virtual TlsAeadCipher CreateCipher_Aes_Gcm(TlsCryptoParameters cryptoParams, int cipherKeySize, int macSize)
Parameters
cryptoParamsTlsCryptoParameterscipherKeySizeintmacSizeint
Returns
CreateCipher_Aria_Gcm(TlsCryptoParameters, int, int)
protected virtual TlsAeadCipher CreateCipher_Aria_Gcm(TlsCryptoParameters cryptoParams, int cipherKeySize, int macSize)
Parameters
cryptoParamsTlsCryptoParameterscipherKeySizeintmacSizeint
Returns
CreateCipher_Camellia_Gcm(TlsCryptoParameters, int, int)
protected virtual TlsAeadCipher CreateCipher_Camellia_Gcm(TlsCryptoParameters cryptoParams, int cipherKeySize, int macSize)
Parameters
cryptoParamsTlsCryptoParameterscipherKeySizeintmacSizeint
Returns
CreateCipher_Cbc(TlsCryptoParameters, int, int, int)
protected virtual TlsCipher CreateCipher_Cbc(TlsCryptoParameters cryptoParams, int encryptionAlgorithm, int cipherKeySize, int macAlgorithm)
Parameters
cryptoParamsTlsCryptoParametersencryptionAlgorithmintcipherKeySizeintmacAlgorithmint
Returns
CreateCipher_SM4_Ccm(TlsCryptoParameters)
protected virtual TlsAeadCipher CreateCipher_SM4_Ccm(TlsCryptoParameters cryptoParams)
Parameters
cryptoParamsTlsCryptoParameters
Returns
CreateCipher_SM4_Gcm(TlsCryptoParameters)
protected virtual TlsAeadCipher CreateCipher_SM4_Gcm(TlsCryptoParameters cryptoParams)
Parameters
cryptoParamsTlsCryptoParameters
Returns
CreateDHDomain(TlsDHConfig)
Create a domain object supporting the domain parameters described in dhConfig.
public override TlsDHDomain CreateDHDomain(TlsDHConfig dhConfig)
Parameters
dhConfigTlsDHConfigthe config describing the DH parameters to use.
Returns
- TlsDHDomain
a TlsDHDomain supporting the parameters in dhConfig.
CreateDesEdeEngine()
protected virtual IBlockCipher CreateDesEdeEngine()
Returns
CreateDigest(int)
public virtual IDigest CreateDigest(int cryptoHashAlgorithm)
Parameters
cryptoHashAlgorithmint
Returns
CreateECDomain(TlsECConfig)
Create a domain object supporting the domain parameters described in ecConfig.
public override TlsECDomain CreateECDomain(TlsECConfig ecConfig)
Parameters
ecConfigTlsECConfigthe config describing the EC parameters to use.
Returns
- TlsECDomain
a TlsECDomain supporting the parameters in ecConfig.
CreateGcmMode(IBlockCipher)
protected virtual IAeadCipher CreateGcmMode(IBlockCipher engine)
Parameters
engineIBlockCipher
Returns
CreateHash(int)
Create a suitable hash for the hash algorithm identifier passed in.
public override TlsHash CreateHash(int cryptoHashAlgorithm)
Parameters
cryptoHashAlgorithmintthe hash algorithm the hash needs to implement.
Returns
Remarks
See enumeration class CryptoHashAlgorithm for appropriate argument values.
CreateHmac(int)
Create a suitable HMAC for the MAC algorithm identifier passed in.
public override TlsHmac CreateHmac(int macAlgorithm)
Parameters
macAlgorithmintthe MAC algorithm the HMAC needs to match.
Returns
Remarks
See enumeration class MacAlgorithm for appropriate argument values.
CreateHmacForHash(int)
Create a suitable HMAC using the hash algorithm identifier passed in.
public override TlsHmac CreateHmacForHash(int cryptoHashAlgorithm)
Parameters
cryptoHashAlgorithmintthe hash algorithm the HMAC should use.
Returns
Remarks
See enumeration class CryptoHashAlgorithm for appropriate argument values.
CreateHmac_Ssl(int)
protected virtual TlsHmac CreateHmac_Ssl(int macAlgorithm)
Parameters
macAlgorithmint
Returns
CreateKemDomain(TlsKemConfig)
Create a domain object supporting the domain parameters described in kemConfig.
public override TlsKemDomain CreateKemDomain(TlsKemConfig kemConfig)
Parameters
kemConfigTlsKemConfigthe config describing the KEM parameters to use.
Returns
- TlsKemDomain
a TlsKemDomain supporting the parameters in kemConfig.
CreateMac(TlsCryptoParameters, int)
protected virtual TlsHmac CreateMac(TlsCryptoParameters cryptoParams, int macAlgorithm)
Parameters
cryptoParamsTlsCryptoParametersmacAlgorithmint
Returns
CreateNonceGenerator(byte[])
Create a nonce generator.
public override TlsNonceGenerator CreateNonceGenerator(byte[] additionalSeedMaterial)
Parameters
additionalSeedMaterialbyte[]context-specific seed material
Returns
Remarks
Each call should construct a new generator, and the generator should be returned from this call only after automatically seeding from this TlsCrypto's entropy source, and from the provided additional seed material. The output of each returned generator must be completely independent of the others.
CreateNonceGenerator(ReadOnlySpan<byte>)
public override TlsNonceGenerator CreateNonceGenerator(ReadOnlySpan<byte> additionalSeedMaterial)
Parameters
additionalSeedMaterialReadOnlySpan<byte>
Returns
CreateNullCipher(TlsCryptoParameters, int)
protected virtual TlsNullCipher CreateNullCipher(TlsCryptoParameters cryptoParams, int macAlgorithm)
Parameters
cryptoParamsTlsCryptoParametersmacAlgorithmint
Returns
CreateSM4Engine()
protected virtual IBlockCipher CreateSM4Engine()
Returns
CreateSecret(byte[])
Create a TlsSecret object based on provided data.
public override TlsSecret CreateSecret(byte[] data)
Parameters
databyte[]the data to base the TlsSecret on.
Returns
- TlsSecret
a TlsSecret based on the provided data.
CreateSeedEngine()
protected virtual IBlockCipher CreateSeedEngine()
Returns
CreateSrp6Client(TlsSrpConfig)
Create an SRP-6 client.
public override TlsSrp6Client CreateSrp6Client(TlsSrpConfig srpConfig)
Parameters
srpConfigTlsSrpConfigclient config.
Returns
- TlsSrp6Client
an initialised SRP6 client object.
CreateSrp6Server(TlsSrpConfig, BigInteger)
Create an SRP-6 server.
public override TlsSrp6Server CreateSrp6Server(TlsSrpConfig srpConfig, BigInteger srpVerifier)
Parameters
srpConfigTlsSrpConfigserver config.
srpVerifierBigIntegerthe SRP6 verifier value.
Returns
- TlsSrp6Server
an initialised SRP6 server object.
CreateSrp6VerifierGenerator(TlsSrpConfig)
Create an SRP-6 verifier generator.
public override TlsSrp6VerifierGenerator CreateSrp6VerifierGenerator(TlsSrpConfig srpConfig)
Parameters
srpConfigTlsSrpConfiggenerator config.
Returns
- TlsSrp6VerifierGenerator
an initialized SRP6 verifier generator.
GenerateRsaPreMasterSecret(ProtocolVersion)
Create a TlsSecret object containing a randomly-generated RSA PreMasterSecret
public override TlsSecret GenerateRsaPreMasterSecret(ProtocolVersion version)
Parameters
versionProtocolVersion
Returns
- TlsSecret
a TlsSecret containing the PreMasterSecret.
HasAnyStreamVerifiers(IList<SignatureAndHashAlgorithm>)
Return true if this TlsCrypto would use a stream verifier for any of the passed in algorithms.
public override bool HasAnyStreamVerifiers(IList<SignatureAndHashAlgorithm> signatureAndHashAlgorithms)
Parameters
signatureAndHashAlgorithmsIList<SignatureAndHashAlgorithm>A list of SignatureAndHashAlgorithm values.
Returns
- bool
true if this instance would use a stream verifier for any of the passed in algorithms, otherwise false.
Remarks
This method is only relevant to handshakes negotiating (D)TLS 1.2.
HasAnyStreamVerifiersLegacy(short[])
Return true if this TlsCrypto would use a stream verifier for any of the passed in algorithms.
public override bool HasAnyStreamVerifiersLegacy(short[] clientCertificateTypes)
Parameters
clientCertificateTypesshort[]An array of ClientCertificateType values.
Returns
- bool
true if this instance would use a stream verifier for any of the passed in algorithms, otherwise false.
Remarks
This method is only relevant to handshakes negotiating (D)TLS versions older than 1.2.
HasCryptoHashAlgorithm(int)
Return true if this TlsCrypto can support the passed in hash algorithm.
public override bool HasCryptoHashAlgorithm(int cryptoHashAlgorithm)
Parameters
cryptoHashAlgorithmintthe algorithm of interest.
Returns
- bool
true if cryptoHashAlgorithm is supported, false otherwise.
HasCryptoSignatureAlgorithm(int)
Return true if this TlsCrypto can support the passed in signature algorithm (not necessarily in combination with EVERY hash algorithm).
public override bool HasCryptoSignatureAlgorithm(int cryptoSignatureAlgorithm)
Parameters
cryptoSignatureAlgorithmintthe algorithm of interest.
Returns
- bool
true if cryptoSignatureAlgorithm is supported, false otherwise.
HasDHAgreement()
Return true if this TlsCrypto can support DH key agreement.
public override bool HasDHAgreement()
Returns
- bool
true if this instance can support DH key agreement, false otherwise.
HasECDHAgreement()
Return true if this TlsCrypto can support ECDH key agreement.
public override bool HasECDHAgreement()
Returns
- bool
true if this instance can support ECDH key agreement, false otherwise.
HasEncryptionAlgorithm(int)
Return true if this TlsCrypto can support the passed in block/stream encryption algorithm.
public override bool HasEncryptionAlgorithm(int encryptionAlgorithm)
Parameters
encryptionAlgorithmintthe algorithm of interest.
Returns
- bool
true if encryptionAlgorithm is supported, false otherwise.
HasHkdfAlgorithm(int)
Return true if this TlsCrypto can support HKDF with the passed in hash algorithm.
public override bool HasHkdfAlgorithm(int cryptoHashAlgorithm)
Parameters
cryptoHashAlgorithmintthe algorithm of interest.
Returns
- bool
true if HKDF is supported with cryptoHashAlgorithm, false otherwise.
HasKemAgreement()
Return true if this TlsCrypto can support KEM key agreement.
public override bool HasKemAgreement()
Returns
- bool
true if this instance can support KEM key agreement, false otherwise.
HasMacAlgorithm(int)
Return true if this TlsCrypto can support the passed in MAC algorithm.
public override bool HasMacAlgorithm(int macAlgorithm)
Parameters
macAlgorithmintthe algorithm of interest.
Returns
- bool
true if macAlgorithm is supported, false otherwise.
HasNamedGroup(int)
Return true if this TlsCrypto supports the passed in named group value.
public override bool HasNamedGroup(int namedGroup)
Parameters
namedGroupint
Returns
- bool
true if this instance supports the passed in named group value.
HasRsaEncryption()
Return true if this TlsCrypto can support RSA encryption/decryption.
public override bool HasRsaEncryption()
Returns
- bool
true if this instance can support RSA encryption/decryption, false otherwise.
HasSignatureAlgorithm(short)
Return true if this TlsCrypto can support the passed in signature algorithm (not necessarily in combination with EVERY hash algorithm).
public override bool HasSignatureAlgorithm(short signatureAlgorithm)
Parameters
signatureAlgorithmshort
Returns
- bool
true if signatureAlgorithm is supported, false otherwise.
HasSignatureAndHashAlgorithm(SignatureAndHashAlgorithm)
Return true if this TlsCrypto can support the passed in signature algorithm.
public override bool HasSignatureAndHashAlgorithm(SignatureAndHashAlgorithm sigAndHashAlgorithm)
Parameters
sigAndHashAlgorithmSignatureAndHashAlgorithmthe algorithm of interest.
Returns
- bool
true if sigAndHashAlgorithm is supported, false otherwise.
HasSignatureScheme(int)
Return true if this TlsCrypto can support the passed in signature scheme.
public override bool HasSignatureScheme(int signatureScheme)
Parameters
signatureSchemeintthe scheme of interest.
Returns
- bool
true if signatureScheme is supported, false otherwise.
HasSrpAuthentication()
Return true if this TlsCrypto can support SRP authentication.
public override bool HasSrpAuthentication()
Returns
- bool
true if this instance can support SRP authentication, false otherwise.
HkdfInit(int)
Setup an initial "secret" for a chain of HKDF calls (RFC 5869), containing a string of HashLen zeroes.
public override TlsSecret HkdfInit(int cryptoHashAlgorithm)
Parameters
cryptoHashAlgorithmintthe hash algorithm to instantiate HMAC with. See CryptoHashAlgorithm for values.