Table of Contents

Class CypherCodec

Namespace
Arc4u.Security.Cryptography
Assembly
Arc4u.dll

Encrypts and decrypts strings with AES-GCM. A random nonce is generated for each value, so the same key can safely protect many values, and any modification of the cypher text (or a wrong key) is detected when decrypting.

public static class CypherCodec
Inheritance
CypherCodec
Inherited Members

Methods

Decrypt(string, byte[])

Decrypts a text produced by Encrypt(string, byte[]).

public static string Decrypt(string cypherText, byte[] key)

Parameters

cypherText string

The base64 cypher text.

key byte[]

The AES key.

Returns

string

The clear text.

Exceptions

FormatException

The cypher text is not in the expected format.

AuthenticationTagMismatchException

The key is wrong or the cypher text was modified.

Encrypt(string, byte[])

Encrypts a text with AES-GCM. A new random nonce is generated for each call.

public static string Encrypt(string clearText, byte[] key)

Parameters

clearText string

The clear text.

key byte[]

The AES key (16, 24 or 32 bytes).

Returns

string

The base64 of nonce, tag and cypher text.

GenerateKey()

Generates a random 256 bits key to use with Encrypt(string, byte[]).

public static string GenerateKey()

Returns

string

The base64 encoded key.