Ejemplo n.º 1
0
        // Token: 0x060000A1 RID: 161 RVA: 0x00009650 File Offset: 0x00007850
        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("\r\n\0".ToCharArray());
                result = text;
            }
            catch
            {
                result = text;
            }
            return(result);
        }
Ejemplo n.º 2
0
        // Token: 0x06000069 RID: 105 RVA: 0x00007F28 File Offset: 0x00006128
        public virtual void Init(bool forEncryption, ICipherParameters parameters)
        {
            this.bool_0 = forEncryption;
            this.byte_7 = null;
            if (parameters is AeadParameters)
            {
                AeadParameters aeadParameters = (AeadParameters)parameters;
                this.byte_1 = aeadParameters.GetNonce();
                this.byte_2 = aeadParameters.GetAssociatedText();
                int macSize = aeadParameters.MacSize;
                if (macSize < 96 || macSize > 128 || macSize % 8 != 0)
                {
                    throw new ArgumentException("Invalid value for MAC size: " + macSize.ToString());
                }
                this.int_0          = macSize / 8;
                this.keyParameter_0 = aeadParameters.Key;
            }
            else
            {
                if (!(parameters is ParametersWithIV))
                {
                    throw new ArgumentException("invalid parameters passed to GCM");
                }
                ParametersWithIV parametersWithIV = (ParametersWithIV)parameters;
                this.byte_1         = parametersWithIV.GetIV();
                this.byte_2         = null;
                this.int_0          = 16;
                this.keyParameter_0 = (KeyParameter)parametersWithIV.Parameters;
            }
            int num = forEncryption ? 16 : (16 + this.int_0);

            this.byte_6 = new byte[num];
            if (this.byte_1 == null || this.byte_1.Length < 1)
            {
                throw new ArgumentException("IV must be at least 1 byte");
            }
            if (this.byte_2 == null)
            {
                this.byte_2 = new byte[0];
            }
            this.iblockCipher_0.Init(true, this.keyParameter_0);
            this.byte_3 = new byte[16];
            this.iblockCipher_0.ProcessBlock(this.byte_3, 0, this.byte_3, 0);
            this.igcmMultiplier_0.Init(this.byte_3);
            this.byte_4 = this.method_3(this.byte_2);
            if (this.byte_1.Length == 12)
            {
                this.byte_5 = new byte[16];
                Array.Copy(this.byte_1, 0, this.byte_5, 0, this.byte_1.Length);
                this.byte_5[15] = 1;
            }
            else
            {
                this.byte_5 = this.method_3(this.byte_1);
                byte[] byte_ = new byte[16];
                GcmBlockCipher.smethod_0((ulong)((long)this.byte_1.Length * 8L), byte_, 8);
                Class8.smethod_9(this.byte_5, byte_);
                this.igcmMultiplier_0.MultiplyH(this.byte_5);
            }
            this.byte_8  = Arrays.Clone(this.byte_4);
            this.byte_9  = Arrays.Clone(this.byte_5);
            this.int_1   = 0;
            this.ulong_0 = 0UL;
        }