コード例 #1
0
        /// <summary>
        /// Sign input plaintext bytes into checksum bytes.
        /// </summary>
        /// <param name="input">The specified plaintext bytes.</param>
        /// <param name="type">The specified checksum algorithm.</param>
        /// <param name="key">The specified key.</param>
        /// <returns>The signed checksum bytes.</returns>
        internal static byte[] Sign(byte[] input, PAC_SIGNATURE_DATA_SignatureType_Values type, byte[] key)
        {
            switch (type)
            {
            case PAC_SIGNATURE_DATA_SignatureType_Values.HMAC_SHA1_96_AES128:
                return(HmacSha1AesChecksum.GetMic(
                           key,
                           input,
                           PacSignatureData.KerbNonKerbCksumSalt,
                           AesKeyType.Aes128BitsKey));

            case PAC_SIGNATURE_DATA_SignatureType_Values.HMAC_SHA1_96_AES256:
                return(HmacSha1AesChecksum.GetMic(
                           key,
                           input,
                           PacSignatureData.KerbNonKerbCksumSalt,
                           AesKeyType.Aes256BitsKey));

            case PAC_SIGNATURE_DATA_SignatureType_Values.KERB_CHECKSUM_HMAC_MD5:
                return(HmacMd5StringChecksum.GetMic(
                           key,
                           input,
                           PacSignatureData.KerbNonKerbCksumSalt));

            default:
                throw new ArgumentOutOfRangeException("type");
            }
        }
コード例 #2
0
        /// <summary>
        /// Generate checksum supported by MS-KILE
        /// </summary>
        /// <param name="key">the key</param>
        /// <param name="input">input data</param>
        /// <param name="usage">key usage number</param>
        /// <param name="checksumType">checksum type</param>
        /// <returns>the caculated checksum</returns>
        /// <exception cref="ArgumentException">thrown if the checksum type is not supported</exception>
        public static byte[] GetChecksum(
            byte[] key,
            byte[] input,
            int usage,
            ChecksumType checksumType)
        {
            switch (checksumType)
            {
            case ChecksumType.CRC32:
            case ChecksumType.rsa_md4:
            case ChecksumType.rsa_md5:
            case ChecksumType.sha1:
                return(UnkeyedChecksum.GetMic(input, checksumType));

            case ChecksumType.hmac_sha1_96_aes128:
                return(HmacSha1AesChecksum.GetMic(
                           key, input, usage, AesKeyType.Aes128BitsKey));

            case ChecksumType.hmac_sha1_96_aes256:
                return(HmacSha1AesChecksum.GetMic(
                           key, input, usage, AesKeyType.Aes256BitsKey));

            case ChecksumType.hmac_md5_string:
                return(HmacMd5StringChecksum.GetMic(key, input, usage));

            default:
                throw new ArgumentException("Unsupported checksum type.");
            }
        }