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 MD5DigestTest(string str, string md5Str) { MD5DigestTest(new DefaultMD5Digest(), str, md5Str); MD5DigestTest(new BcMD5Digest(), str, md5Str); MD5DigestTest(new MD5Digest(), str, md5Str); Span <byte> hash = stackalloc byte[HashConstants.Md5Length]; MD5Utils.Fast440(Encoding.UTF8.GetBytes(str), hash); Assert.AreEqual(md5Str, hash.ToHex()); }
public void Fast440() { Span <byte> hash = stackalloc byte[HashConstants.Md5Length]; MD5Utils.Fast440(_randombytes.Span, hash); }