Show / Hide Table of Contents

Interface ICryptoProvider

Namespace: PKWARE.Smartcrypt.Protocol
Assembly: SmartcryptProtocol.dll
Syntax
public interface ICryptoProvider
Remarks

ICryptoProvider is an interface to allow for testing and code translation into another language.

Methods

DecryptAes(Byte[], Byte[], Byte[], Boolean)

Decrypts data using AES with variable key sizes.

Declaration
[NotNull]
byte[] DecryptAes([NotNull] byte[] data, [NotNull] byte[] key, [NotNull] byte[] iv, bool usePadding = true)
Parameters
Type Name Description
Byte[] data

The data to encrypt.

Byte[] key

A valid AES key. May be 16, 24, or 32 bytes.

Byte[] iv

The initialization vector. Must be exactly 16 bytes.

Boolean usePadding

If true, PKCS7 padding will be applied. If false, no padding will be applied.

Returns
Type Description
Byte[]

The non-null, plaintext data.

DecryptRsa(Byte[], Byte[])

Declaration
byte[] DecryptRsa([NotNull] byte[] cipherText, [NotNull] byte[] key)
Parameters
Type Name Description
Byte[] cipherText
Byte[] key
Returns
Type Description
Byte[]

EncryptAes(Byte[], Byte[], Byte[], Boolean)

Encrypts data using AES with variable key sizes.

Declaration
[NotNull]
byte[] EncryptAes([NotNull] byte[] data, [NotNull] byte[] key, [NotNull] byte[] iv, bool usePadding = true)
Parameters
Type Name Description
Byte[] data

The data to encrypt.

Byte[] key

A valid AES key. May be 16, 24, or 32 bytes.

Byte[] iv

The initialization vector. Must be exactly 16 bytes.

Boolean usePadding

If true, PKCS7 padding will be applied. If false, no padding will be applied.

Returns
Type Description
Byte[]

The non-null, ciphertext data.

EncryptRsa(Byte[], Byte[])

Performs RSA public key encryption.

Declaration
[Pure]
[NotNull]
byte[] EncryptRsa([NotNull] byte[] data, [NotNull] byte[] key)
Parameters
Type Name Description
Byte[] data

The data to encrypt.

Byte[] key

The RSA public key. Must be in the PKCS1 ASN.1 format.

Returns
Type Description
Byte[]

The non-null, ciphertext data.

Exceptions
Type Condition
ArgumentException

If the key does not appear to be a RSA public key in the PKCS1 ASN.1 format, or if the array of data to encrypt is larger than allowed given the key size.

GenerateBytes(Int32)

Generates cryptographically-secure random bytes.

Declaration
[NotNull]
byte[] GenerateBytes(int count)
Parameters
Type Name Description
Int32 count

The number of bytes to generate.

Returns
Type Description
Byte[]

GenerateRsaKeyPair()

Declaration
[NotNull]
RsaKeyPair GenerateRsaKeyPair()
Returns
Type Description
RsaKeyPair

HmacSha256(Byte[], Byte[])

Declaration
[NotNull]
byte[] HmacSha256([NotNull] byte[] key, [NotNull] byte[] data)
Parameters
Type Name Description
Byte[] key
Byte[] data
Returns
Type Description
Byte[]

IsRsaPrivateKey(Byte[])

Verifies whether or not a byte[] is a RSA private key.

Declaration
[ContractAnnotation("key:null => false")]
bool IsRsaPrivateKey([CanBeNull] byte[] key)
Parameters
Type Name Description
Byte[] key

The proposed key. Should be in the PKCS1 ASN.1 format.

Returns
Type Description
Boolean

true if the provided key is a RSA private key in the PKCS1 ASN.1 format, otherwise false.

Pbkdf2HmacSha256(String, Byte[], Int32, Int32)

Declaration
[NotNull]
byte[] Pbkdf2HmacSha256([NotNull] string password, [NotNull] byte[] salt, int iterations, int keyLength)
Parameters
Type Name Description
String password
Byte[] salt
Int32 iterations
Int32 keyLength
Returns
Type Description
Byte[]

Sha1(Byte[])

Declaration
[NotNull]
byte[] Sha1([NotNull] byte[] data)
Parameters
Type Name Description
Byte[] data
Returns
Type Description
Byte[]

Sha256(Byte[])

Declaration
[NotNull]
byte[] Sha256([NotNull] byte[] data)
Parameters
Type Name Description
Byte[] data
Returns
Type Description
Byte[]

SignRsa(Byte[], Byte[])

Performs an RSA signature of the plain text.

Declaration
byte[] SignRsa([NotNull] byte[] plainText, [NotNull] byte[] key)
Parameters
Type Name Description
Byte[] plainText

To sign.

Byte[] key

The private key to use.

Returns
Type Description
Byte[]
Remarks

SHA512 should be used as the hashing algorithm. No padding should be used during signing.

VerifyRsa(Byte[], Byte[], Byte[])

Verifies the integrity of data by checking the RSA signature.

Declaration
[Pure]
bool VerifyRsa([NotNull] byte[] data, [NotNull] byte[] signature, [NotNull] byte[] key)
Parameters
Type Name Description
Byte[] data

The data to verify the signature of.

Byte[] signature

The RSA signature.

Byte[] key

The RSA public key. Must be in the PKCS1 ASN.1 format.

Returns
Type Description
Boolean

true if the RSA signature checked out, otherwise false.

Exceptions
Type Condition
ArgumentException

If the key does not appear to be a RSA public key in the PKCS1 ASN.1 format.

Extension Methods

SemanticEncryption.EncryptMasterKey(ICryptoProvider, Byte[], String)
SemanticEncryption.DecryptMasterKey(ICryptoProvider, String, Byte[])
SemanticEncryption.EncryptGroupKey(ICryptoProvider, Byte[], String)
SemanticEncryption.DecryptGroupKey(ICryptoProvider, String, Byte[])
SemanticEncryption.EncryptHybrid(ICryptoProvider, Byte[], String)
SemanticEncryption.DecryptHybrid(ICryptoProvider, String, Byte[])
SmartcryptCrypto.EncryptV7(ICryptoProvider, String, Byte[])
SmartcryptCrypto.EncryptV6(ICryptoProvider, Byte[], Byte[])
SmartcryptCrypto.EncryptV5(ICryptoProvider, Byte[], Byte[])
SmartcryptCrypto.EncryptV4(ICryptoProvider, Byte[], Byte[])
SmartcryptCrypto.DecryptV4(ICryptoProvider, String, Byte[])
SmartcryptCrypto.DecryptV5(ICryptoProvider, String, Byte[])
SmartcryptCrypto.DecryptV6(ICryptoProvider, String, Byte[])
SmartcryptCrypto.DecryptV7(ICryptoProvider, String, Byte[])
SmartcryptCrypto.VerifySignature(ICryptoProvider, Byte[], String, String)
SmartcryptCrypto.GenerateKeyFromPassword(ICryptoProvider, String, String, Int32)
SmartcryptCrypto.EncryptV2(ICryptoProvider, Byte[], String)
SmartcryptCrypto.DecryptV2(ICryptoProvider, String, Byte[])
SmartcryptCrypto.Sign(ICryptoProvider, Byte[], String)
SmartcryptCrypto.EncryptV3(ICryptoProvider, Byte[], Byte[], Int32)
SmartcryptCrypto.DecryptV3(ICryptoProvider, String, Byte[])
In This Article
  • Methods
    • DecryptAes(Byte[], Byte[], Byte[], Boolean)
    • DecryptRsa(Byte[], Byte[])
    • EncryptAes(Byte[], Byte[], Byte[], Boolean)
    • EncryptRsa(Byte[], Byte[])
    • GenerateBytes(Int32)
    • GenerateRsaKeyPair()
    • HmacSha256(Byte[], Byte[])
    • IsRsaPrivateKey(Byte[])
    • Pbkdf2HmacSha256(String, Byte[], Int32, Int32)
    • Sha1(Byte[])
    • Sha256(Byte[])
    • SignRsa(Byte[], Byte[])
    • VerifyRsa(Byte[], Byte[], Byte[])
  • Extension Methods
Back to top Copyright © 2018 PKWARE, Inc.