コード例 #1
0
        /// <summary>復号化</summary>
        /// <param name="input">AeadResult</param>
        /// <returns>平文(plaintext)</returns>
        public override byte[] Decrypt(AeadResult input)
        {
            // 初期化
            this.InitAesCbc(false);

            //認証タグ(MAC)を取得
            // Concatenate the [AAD], the [Initialization Vector], the [ciphertext], and the [AL value].
            byte[] temp = ArrayOperator.CombineArray(this.AAD, this.IV);
            temp = ArrayOperator.CombineArray(temp, input.Ciphert);
            temp = ArrayOperator.CombineArray(temp, this.AL);
            byte[] tag = this._hmac.ComputeHash(temp);
            Array.Resize(ref tag, TAG_LEN);

            // タグの確認
            if (!tag.SequenceEqual(input.Tag))
            {
                return(null);
            }

            // CCM操作の実行
            byte[] plaint = new byte[this._aesCBC.GetOutputSize(input.Ciphert.Length)];
            int    len    = this._aesCBC.ProcessBytes(input.Ciphert, 0, input.Ciphert.Length, plaint, 0);

            len += this._aesCBC.DoFinal(plaint, len);
            Array.Resize(ref plaint, len);

            // 平文を返す。
            return(plaint);
        }
コード例 #2
0
        /// <summary>復号化</summary>
        /// <param name="input">AeadResult</param>
        /// <returns>平文(plaintext)</returns>
        public override byte[] Decrypt(AeadResult input)
        {
            // AesGcm実装を初期化
            this.InitAesGcm(false);

            // aead = ciphert + tag
            byte[] aead = null;
            if (input.Aead == null)
            {
                aead = input.CombineByteArrayForDecrypt();
            }
            else
            {
                aead = input.Aead;
            }

            // GCM操作の実行
            byte[] plaint = new byte[this._aesGcm.GetOutputSize(aead.Length)];
            int    len    = this._aesGcm.ProcessBytes(aead, 0, aead.Length, plaint, 0);

            len += this._aesGcm.DoFinal(plaint, len);

            // 平文を返す。
            return(plaint);
        }