コード例 #1
0
        /// <summary>
        /// Generate key according to password, salt and encryption type
        /// </summary>
        /// <param name="type">encryption type</param>
        /// <param name="password">password</param>
        /// <param name="salt">salt</param>
        /// <returns>the generated key in bytes</returns>
        public static byte[] MakeKey(EncryptionType type, string password, string salt)
        {
            switch (type)
            {
            case EncryptionType.AES128_CTS_HMAC_SHA1_96:
            {
                return(AesKey.MakeStringToKey(password, salt,
                                              AesKey.DEFAULT_ITERATION_COUNT, AesKeyType.Aes128BitsKey));
            }

            case EncryptionType.AES256_CTS_HMAC_SHA1_96:
            {
                return(AesKey.MakeStringToKey(password, salt,
                                              AesKey.DEFAULT_ITERATION_COUNT, AesKeyType.Aes256BitsKey));
            }

            case EncryptionType.DES_CBC_CRC:
            case EncryptionType.DES_CBC_MD5:
            {
                return(DesKey.MakeStringToKey(password, salt));
            }

            case EncryptionType.RC4_HMAC:
            case EncryptionType.RC4_HMAC_EXP:
            {
                return(Rc4Key.MakeStringToKey(password));
            }

            default:
                throw new ArgumentException("Unsupported encryption type.");
            }
        }
コード例 #2
0
        private static byte[] RandomToKey(EncryptionType type, byte[] random)
        {
            switch (type)
            {
            case EncryptionType.AES256_CTS_HMAC_SHA1_96:
            case EncryptionType.AES128_CTS_HMAC_SHA1_96:
            {
                return(AesKey.RandomToKey(random));
            }

            case EncryptionType.DES_CBC_CRC:
            case EncryptionType.DES_CBC_MD5:
            {
                return(DesKey.DesRandomToKey(random));
            }

            case EncryptionType.RC4_HMAC:
            {
                return(Rc4Key.RandomToKey(random));
            }

            default:
                throw new NotSupportedException("Encryption type not support");
            }
        }