How to use the crypt.StreamCipher function in crypt

To help you get started, we’ve selected a few crypt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Moddable-OpenSource / moddable / modules / crypt / ssl / ssl_setup.js View on Github external
function setupSub(o, cipher)
{
	let enc, h;

	switch (cipher.cipherAlgorithm) {
	case DES:
		enc = new BlockCipher("DES", o.key);
		break;
	case TDES:
		enc = new BlockCipher("TDES", o.key);
		break;
	case AES:
		enc = new BlockCipher("AES", o.key);
		break;
	case RC4:
		enc = new StreamCipher("RC4", o.key);
		break;
	default:
		throw new Error("SSL: SetupCipher: unkown encryption algorithm");
	}
	switch (cipher.encryptionMode) {
	case CBC:
	case NONE:
		switch (cipher.hashAlgorithm) {
		case MD5: h = "MD5"; break;
		case SHA1: h = "SHA1"; break;
		case SHA256: h = "SHA256"; break;
		case SHA384: h = "SHA384"; break;
		default:
			throw new Error("SSL: SetupCipher: unknown hash algorithm");
		}
		o.hmac = new HMAC(new Digest(h), o.macSecret);
github Moddable-OpenSource / moddable / examples / crypt / cryptblockcipher / main.js View on Github external
function testStreamCipher(name, keyStr, plain, iv, counter, expected)
{
	let key = ("string" == typeof keyStr) ? ArrayBuffer.fromString(keyStr) : keyStr;

	if ("string" == typeof plain)
		plain += "";

	let result = (new StreamCipher(name, key, iv, counter)).encrypt(plain);

	if (Hex.toString(result) != expected)
		trace(`${name} fail\n`);
	else
		trace(`${name} pass\n`);
}