コード例 #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="security">Used security level.</param>
        /// <param name="encrypt"></param>
        /// <param name="blockCipherKey"></param>
        /// <param name="aad"></param>
        /// <param name="iv"></param>
        /// <param name="tag"></param>
        public GXDLMSChipperingStream(Gurux.DLMS.Enums.Security security, bool encrypt, byte[] blockCipherKey, byte[] aad, byte[] iv, byte[] tag)
        {
            this.Security = security;
            const int TagSize = 0x10;

            this.Tag = tag;
            if (this.Tag == null)//Tag size is 12 bytes.
            {
                this.Tag = new byte[12];
            }
            else if (this.Tag.Length != 12)
            {
                throw new ArgumentOutOfRangeException("Invalid tag.");
            }
            Encrypt    = encrypt;
            WorkingKey = GenerateKey(encrypt, blockCipherKey);
            int bufLength = Encrypt ? BlockSize : (BlockSize + TagSize);

            this.bufBlock = new byte[bufLength];
            Aad           = aad;
            this.H        = new byte[BlockSize];
            ProcessBlock(H, 0, H, 0);
            Init(H);
            this.J0 = new byte[16];
            Array.Copy(iv, 0, J0, 0, iv.Length);
            this.J0[15]         = 0x01;
            this.S              = GetGHash(Aad);
            this.counter        = (byte[])J0.Clone();
            this.BytesRemaining = 0;
            this.totalLength    = 0;
        }
コード例 #2
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="tag">Command.</param>
 /// <param name="security"></param>
 /// <param name="invocationCounter">Invocation counter.</param>
 /// <param name="systemTitle"></param>
 /// <param name="blockCipherKey"></param>
 /// <param name="authenticationKey"></param>
 public AesGcmParameter(
     byte tag,
     Gurux.DLMS.Enums.Security security,
     UInt32 invocationCounter,
     byte[] systemTitle,
     byte[] blockCipherKey,
     byte[] authenticationKey)
 {
     Tag               = tag;
     Security          = security;
     InvocationCounter = invocationCounter;
     SystemTitle       = systemTitle;
     BlockCipherKey    = blockCipherKey;
     AuthenticationKey = authenticationKey;
     Type              = CountType.Packet;
     SecuritySuite     = SecuritySuite.AesGcm128;
 }