/// <summary> /// NetTriplsDESEncryption constructor /// </summary> public NetTripleDESEncryption(string key, int bitsize) { if (!s_keysizes.Contains(bitsize)) { throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_keysizes))); } byte[] entropy = Encoding.UTF32.GetBytes(key); // I know hardcoding salts is bad, but in this case I think it is acceptable. HMACSHA512 hmacsha512 = new HMACSHA512(Convert.FromBase64String("i88NEiez3c50bHqr3YGasDc4p8jRrxJAaiRiqixpvp4XNAStP5YNoC2fXnWkURtkha6M8yY901Gj07IRVIRyGL==")); hmacsha512.Initialize(); for (int i = 0; i < 1000; i++) { entropy = hmacsha512.ComputeHash(entropy); } int keylen = bitsize / 8; m_key = new byte[keylen]; Buffer.BlockCopy(entropy, 0, m_key, 0, keylen); m_iv = new byte[s_blocksizes[0] / 8]; Buffer.BlockCopy(entropy, entropy.Length - m_iv.Length - 1, m_iv, 0, m_iv.Length); m_bitSize = bitsize; }
/// <summary> /// NetTriplsDESEncryption constructor /// </summary> public NetTripleDESEncryption(byte[] key, byte[] iv) { if (!s_keysizes.Contains(key.Length * 8)) { throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_keysizes))); } if (!s_blocksizes.Contains(iv.Length * 8)) { throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_blocksizes))); } m_key = key; m_iv = iv; m_bitSize = m_key.Length * 8; }