protected override void InitCipher(byte[] iv, bool isEncrypt) { base.InitCipher(iv, isEncrypt); _crypto?.Dispose(); if (cipherFamily == CipherFamily.Rc4Md5) { Span <byte> temp = stackalloc byte[keyLen + ivLen]; var realKey = new byte[MD5Length]; key.CopyTo(temp); iv.CopyTo(temp.Slice(keyLen)); MD5Utils.Fast440(temp, realKey); _crypto = StreamCryptoCreate.Rc4(realKey); return; } _crypto = cipherFamily switch { CipherFamily.AesCfb => StreamCryptoCreate.AesCfb(isEncrypt, key, iv), CipherFamily.Chacha20 => StreamCryptoCreate.ChaCha20(key, iv), CipherFamily.Rc4 => StreamCryptoCreate.Rc4(key), _ => throw new NotSupportedException() }; }
public void Test(string keyHex, int originSize, string hex, string hex2) { var key = keyHex.FromHex(); Test(new BcRC4Crypto(key), originSize, hex, hex2); Test(StreamCryptoCreate.Rc4(key), originSize, hex, hex2); }
public void RC4() { Test(StreamCryptoCreate.Rc4(_randomKey), _randombytes.Span); }
protected override IStreamCrypto CreateCrypto(bool isEncrypt, ReadOnlySpan <byte> key, ReadOnlySpan <byte> iv) { return(StreamCryptoCreate.Rc4(key)); }