Skip to content

Symmetric Class ​

Definition ​

Symmetric (block-cipher) encryption built for cross-library interoperability. New encryption uses only standard, documented constructions other tools can reproduce (see INTEROP.md): Raw key: IV ‖ ciphertext (PKCS7, IV prepended) via Encrypt.Password: saltLen ‖ salt ‖ iterations ‖ IV ‖ ciphertext (PBKDF2-HMAC-SHA256) via EncryptWithPassword. Raw CBC is unauthenticated; for authenticated, equally interoperable encryption prefer AesGcm. The previous JASE proprietary format is read-only via DecryptLegacy.

  • Namespace: JASE.Crypto
  • Assembly: JASE.Crypto.dll

Methods ​

NameDescription
byte[] Decrypt(byte[] data, byte[] key, SymmetricAlgorithms algorithm = null, EncryptionPaddingMode padding = null)Decrypts an IV ‖ ciphertext payload produced with a raw key.
string Decrypt(string data, byte[] key, SymmetricAlgorithms algorithm = null, EncryptionPaddingMode padding = null)Decrypts a Base64 IV ‖ ciphertext string produced with a raw key.
byte[] DecryptLegacy(byte[] data, SymmetricAlgorithms algorithm, bool includeIV, string salt, string authKey, EncryptionPaddingMode padding = null)Decrypts data written by the legacy JASE proprietary symmetric format (single SHA-256 key derivation and [bits] framing). Provided decrypt-only for migrating existing data; it is not interoperable with other libraries. Re-encrypt with Encrypt, EncryptWithPassword, or AesGcm.
byte[] DecryptLegacy(byte[] data, byte[] salt, byte[] authKey, SymmetricAlgorithms algorithm, bool includeIV, EncryptionPaddingMode padding = null)Decrypts data written by the legacy JASE proprietary symmetric format using raw key/auth bytes. Decrypt-only; see DecryptLegacy.
string DecryptLegacy(string data, SymmetricAlgorithms algorithm, bool includeIV, string salt, string authKey, EncryptionPaddingMode padding = null)Decrypts a Base64 string written by the legacy JASE proprietary symmetric format. Decrypt-only; see DecryptLegacy.
byte[] DecryptWithPassword(byte[] data, string password, SymmetricAlgorithms algorithm = null, EncryptionPaddingMode padding = null)Decrypts a password container produced by EncryptWithPassword. The salt and iteration count are read from the container.
string DecryptWithPassword(string data, string password, SymmetricAlgorithms algorithm = null, EncryptionPaddingMode padding = null)Decrypts a Base64 password container produced by EncryptWithPassword.
byte[] Encrypt(byte[] data, byte[] key, SymmetricAlgorithms algorithm = null, EncryptionPaddingMode padding = null)Encrypts data with a raw key, producing the interoperable IV ‖ ciphertext layout.
string Encrypt(string data, byte[] key, SymmetricAlgorithms algorithm = null, EncryptionPaddingMode padding = null)Encrypts a string with a raw key, returning Base64 of the interoperable IV ‖ ciphertext layout.
byte[] EncryptWithPassword(byte[] data, string password, byte[] salt, int iterations = null, SymmetricAlgorithms algorithm = null, EncryptionPaddingMode padding = null)Encrypts data with a passphrase using PBKDF2-HMAC-SHA256. The derivation parameters travel with the output so other libraries can reproduce the key. Layout: saltLen(1) ‖ salt ‖ iterations(uint32 BE) ‖ IV ‖ ciphertext.
string EncryptWithPassword(string data, string password, byte[] salt, int iterations = null, SymmetricAlgorithms algorithm = null, EncryptionPaddingMode padding = null)Encrypts a string with a passphrase using PBKDF2-HMAC-SHA256, returning Base64 of the self-describing password container.
byte[] GenerateKey(int length = null)Generates a cryptographically secure random byte array with a specified length for use as a key or IV
bool IsFipsSet()Returns if FIPS bit is set to only allow FIPS approved algorithms indicating runtime should enforce the policy to create only Federal Information Processing Standard (FIPS) certified algorithms.
bool IsValidKey(byte[] key, SymmetricAlgorithms algorithm = null)Determines whether the supplied binary key material meets the legal key-size requirements for the specified symmetric encryption algorithm.
bool IsValidKey(string key, SymmetricAlgorithms algorithm = null)Determines whether the specified key string represents a valid key for the selected symmetric encryption algorithm.