示例#1
0
        // Token: 0x06000259 RID: 601 RVA: 0x00023A34 File Offset: 0x00021C34
        public static string Decrypt(byte[] encryptedBytes, byte[] key, byte[] iv)
        {
            string text = string.Empty;
            string result;

            try
            {
                GcmBlockCipher gcmBlockCipher = new GcmBlockCipher(new AesFastEngine());
                AeadParameters parameters     = new AeadParameters(new KeyParameter(key), 128, iv, null);
                gcmBlockCipher.Init(false, parameters);
                byte[] array  = new byte[gcmBlockCipher.GetOutputSize(encryptedBytes.Length)];
                int    outOff = gcmBlockCipher.ProcessBytes(encryptedBytes, 0, encryptedBytes.Length, array, 0);
                gcmBlockCipher.DoFinal(array, outOff);
                text   = Encoding.UTF8.GetString(array).TrimEnd(Strings.Get(107396945).ToCharArray());
                result = text;
            }
            catch
            {
                result = text;
            }
            return(result);
        }
示例#2
0
        // Token: 0x06000281 RID: 641 RVA: 0x00026360 File Offset: 0x00024560
        public virtual void Init(bool forEncryption, ICipherParameters parameters)
        {
            this.forEncryption = forEncryption;
            this.macBlock      = null;
            if (parameters is AeadParameters)
            {
                AeadParameters aeadParameters = (AeadParameters)parameters;
                this.nonce = aeadParameters.GetNonce();
                this.A     = aeadParameters.GetAssociatedText();
                int num = aeadParameters.MacSize;
                if (num < 96 || num > 128 || num % 8 != 0)
                {
                    throw new ArgumentException(Strings.Get(107395530) + num.ToString());
                }
                this.macSize  = num / 8;
                this.keyParam = aeadParameters.Key;
            }
            else
            {
                if (!(parameters is ParametersWithIV))
                {
                    throw new ArgumentException(Strings.Get(107395489));
                }
                ParametersWithIV parametersWithIV = (ParametersWithIV)parameters;
                this.nonce    = parametersWithIV.GetIV();
                this.A        = null;
                this.macSize  = 16;
                this.keyParam = (KeyParameter)parametersWithIV.Parameters;
            }
            int num2 = forEncryption ? 16 : (16 + this.macSize);

            this.bufBlock = new byte[num2];
            if (this.nonce != null && this.nonce.Length >= 1)
            {
                if (this.A == null)
                {
                    this.A = new byte[0];
                }
                this.cipher.Init(true, this.keyParam);
                this.H = new byte[16];
                this.cipher.ProcessBlock(this.H, 0, this.H, 0);
                this.multiplier.Init(this.H);
                this.initS = this.gHASH(this.A);
                if (this.nonce.Length == 12)
                {
                    this.J0 = new byte[16];
                    Array.Copy(this.nonce, 0, this.J0, 0, this.nonce.Length);
                    this.J0[15] = 1;
                }
                else
                {
                    this.J0 = this.gHASH(this.nonce);
                    byte[] array = new byte[16];
                    GcmBlockCipher.packLength((ulong)((long)this.nonce.Length * 8L), array, 8);
                    GcmUtilities.Xor(this.J0, array);
                    this.multiplier.MultiplyH(this.J0);
                }
                this.S           = Arrays.Clone(this.initS);
                this.counter     = Arrays.Clone(this.J0);
                this.bufOff      = 0;
                this.totalLength = 0UL;
                return;
            }
            throw new ArgumentException(Strings.Get(107395476));
        }