- AES 256
const aesWrapper: AESWrapper = new AESWrapper();
const aesKey = aesWrapper.aes128Key();
const aesNonce = aesWrapper.aesNonce();
const toEncrypt: string = "This is my array to encrypt";
const encoder = new TextEncoder();
const tohashBytes: Array<number> = Array.from(encoder.encode(toEncrypt));
const ciphertext = aesWrapper.aes128Encrypt(aesKey, aesNonce, tohashBytes);
const plaintxt = aesWrapper.aes128Decrypt(aesKey, aesNonce, ciphertext);
-RSA
const rsaWrapper: RSAWrapper = new RSAWrapper();
const keys: RsaKeyPairResult = rsaWrapper.generateKeys(4096);
const tohashed: string = "This is my array to encrypt";
const encoder = new TextEncoder();
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
const ciphertext = rsaWrapper.encrypt(keys.publicKey, tohashBytes);
const plaintext = rsaWrapper.decrypt(keys.privateKey, ciphertext);
-ED25519 SHA
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA256)
const toHash: string = "This is my array to encrypt";
const encoder = new TextEncoder();
const toHashBytes: Array<number> = Array.from(encoder.encode(toHash));
const dsResult = shaDsWrapper.createED25519(toHashBytes);
const verify = shaDsWrapper.verifyED25519(dsResult.publicKey, toHashBytes, dsResult.signature);
-RSA SHA
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA512)
const tohashed: string = "This is my array to encrypt";
const notOriginal: string = "This is not a fun time";
const encoder = new TextEncoder();
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
const badBytes: Array<number> = Array.from(encoder.encode(notOriginal));
const dsResult: RSADigitalSignatureResult = shaDsWrapper.createRsa(4096, tohashBytes);
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, badBytes, dsResult.signature);
-SHA3 512
const wrapper = new SHAWrapper();
const tohashed: string = "This is my array to hash";
const encoder = new TextEncoder();
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
const hashed = wrapper.hash512(tohashBytes);
-SHA3 256
const wrapper = new SHAWrapper();
const tohashed: string = "This is my array to hash";
const encoder = new TextEncoder();
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
const hashed = wrapper.hash256(tohashBytes);
-AES/RSA Encryption
const hybridWrapper = new HybridEncryptionWrapper();
let initalizer = new AESRSAHybridInitializer(128, 4096);
const tohashed: string = "This is my encrypt text for rsa hybrid";
const encoder = new TextEncoder();
const toEncrypt: Array<number> = Array.from(encoder.encode(tohashed));
let result: AesRsaHybridEncryptResult = hybridWrapper.encrypt(toEncrypt, initalizer);
let plaintext: Array<number> = hybridWrapper.decrypt(initalizer.rsaKeyPair.privateKey, result);
-X25519
const wrapper = new X25519Wrapper();
const alice = wrapper.generateSecretAndPublicKey();
const bob = wrapper.generateSecretAndPublicKey();
const alice_shared_secret = wrapper.generateSharedSecret(
alice.secretKey,
bob.publicKey,
);
const bob_shared_secret = wrapper.generateSharedSecret(
bob.secretKey,
alice.publicKey,
);
var result = areEqual(alice_shared_secret, bob_shared_secret);
-Ascon 128
const wrapper: AsconWrapper = new AsconWrapper();
const key: Array<number> = wrapper.ascon128Key();
const nonce: Array<number> = wrapper.ascon128Nonce();
const tohashed: string = "This is my array to encrypt";
const encoder = new TextEncoder();
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
const ciphertext = wrapper.ascon128Encrypt(key, nonce, tohashBytes);
const plaintext = wrapper.ascon128Decrypt(key, nonce, ciphertext);
- BCrypt
const hasher: BCryptWrapper = new BCryptWrapper();
const password: string = "ThisOneBadPassword!@";
const hashedPassword: string = hasher.hashPassword(password);
- SCrypt
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
PasswordHasherType.Scrypt,
);
const password: string = "ScryptRocks";
const hashed: string = hasher.hashPassword(password);
- Argon2
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
PasswordHasherType.Argon2,
);
const password: string = "ScryptRocks";
const hashed: string = hasher.hashPassword(password);