Cryptography

Encrypt, Decrypt, Hash, Sign and Verify

Encrypt takes the input data and hands back the encrypted bytes. Decrypt hands back the decrypted value as text. Hash hands back the digest for the algorithm chosen. Sign hands back a signature over the input, and Verify answers whether the signature set with WithSignature matches the input. GenerateKey and GenerateIV produce key material rather than consuming it, and both leave what they made on the chain so the operation after them uses it. GenerateIV is an AES call; RSA and the signing algorithms have no initialization vector. Every one of these returns the configuration interface, so several operations can run off one setup.

WARNING

GPAL does not store key material anywhere. A key, iv or key pair that a workflow generates and does not keep cannot be recovered, and the data encrypted with it cannot be read again.

Examples

GPAL Fluent: High-level fluent C# API

//Decrypt needs the same algorithm, key, mode and iv the data was encrypted with. Hold the key and iv the workflow generated, or supply your own with WithKey and WithIV. Signing reads as one chain because the key swaps in the middle: the private key signs, then WithKey takes the public one and Verify checks the signature against the same input. SHA256withRSA works the same way with an RSA pair.

byte[] encrypted;

string plain;


GPAL.Cryptography

.WithAlgorithm(CryptoAlgorithm.AES)

.WithKey(key)

.WithIV(iv)

.WithInputData(Encoding.UTF8.GetBytes("account number 12345"))

.Encrypt(out encrypted);


GPAL.Cryptography

.WithAlgorithm(CryptoAlgorithm.AES)

.WithKey(key)

.WithIV(iv)

.WithInputData(encrypted)

.Decrypt(out plain);


// signed with the private key, checked with the public one

GPAL.Cryptography

.WithAlgorithm(CryptoAlgorithm.ECDSA)

.WithKey(ecPrivate)

.WithInputData(payload)

.Sign(out byte[] signature)

.WithKey(ecPublic)

.WithSignature(signature)

.Verify(out bool isValid);

💬 Ask GPAL