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 |
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 |
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 |
Returns
Type | Description |
---|---|
Byte[] | The non-null, ciphertext data. |
Exceptions
Type | Condition |
---|---|
ArgumentException | If the |
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 |
Returns
Type | Description |
---|---|
Boolean |
|
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 |
Returns
Type | Description |
---|---|
Boolean |
|
Exceptions
Type | Condition |
---|---|
ArgumentException | If the |