示例#1
0
        private static string GenerateHash(string email, byte[] passwordAesKey)
        {
            byte[] emailBytes = email.ToBytes();
            byte[] hash       = new byte[16];

            // Compute email in 16 bytes array
            for (int i = 0; i < emailBytes.Length; i++)
            {
                hash[i % 16] ^= emailBytes[i];
            }

            // Encrypt hash using password key
            using (var encryptor = Crypto.CreateAesEncryptor(passwordAesKey))
            {
                for (int it = 0; it < 16384; it++)
                {
                    hash = Crypto.EncryptAes(hash, encryptor);
                }
            }

            // Retrieve bytes 0-4 and 8-12 from the hash
            byte[] result = new byte[8];
            Array.Copy(hash, 0, result, 0, 4);
            Array.Copy(hash, 8, result, 4, 4);

            return(result.ToBase64());
        }
示例#2
0
        protected MegaAesCtrStream(Stream stream, long streamLength, Mode mode, byte[] fileKey, byte[] iv)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (fileKey == null || fileKey.Length != 16)
            {
                throw new ArgumentException("Invalid fileKey");
            }

            if (iv == null || iv.Length != 8)
            {
                throw new ArgumentException("Invalid Iv");
            }

            this.stream       = stream;
            this.streamLength = streamLength;
            this.mode         = mode;
            this.fileKey      = fileKey;
            this.iv           = iv;

            this.ChunksPositions      = this.GetChunksPositions(this.streamLength).ToArray();
            this.chunksPositionsCache = new HashSet <long>(this.ChunksPositions);

            this.encryptor = Crypto.CreateAesEncryptor(this.fileKey);
        }
示例#3
0
文件: Crypto.cs 项目: zha0/Cerberus
 // Token: 0x060007EF RID: 2031 RVA: 0x00039820 File Offset: 0x00037A20
 public static byte[] EncryptAes(byte[] data, byte[] key)
 {
     byte[] result;
     using (ICryptoTransform cryptoTransform = Crypto.CreateAesEncryptor(key))
     {
         result = cryptoTransform.TransformFinalBlock(data, 0, data.Length);
     }
     return(result);
 }
示例#4
0
文件: Crypto.cs 项目: zha0/Cerberus
 // Token: 0x060007EA RID: 2026 RVA: 0x000396CC File Offset: 0x000378CC
 public static byte[] EncryptKey(byte[] data, byte[] key)
 {
     byte[] array = new byte[data.Length];
     using (ICryptoTransform cryptoTransform = Crypto.CreateAesEncryptor(key))
     {
         for (int i = 0; i < data.Length; i += 16)
         {
             Array.Copy(Crypto.EncryptAes(data.CopySubArray(16, i), cryptoTransform), 0, array, i, 16);
         }
     }
     return(array);
 }
示例#5
0
 // Token: 0x0600094F RID: 2383 RVA: 0x0004C2F0 File Offset: 0x0004A4F0
 private static string GenerateHash(string email, byte[] passwordAesKey)
 {
     byte[] array  = email.ToBytes();
     byte[] array2 = new byte[16];
     for (int i = 0; i < array.Length; i++)
     {
         byte[] array3 = array2;
         int    num    = i % 16;
         array3[num] ^= array[i];
     }
     using (ICryptoTransform cryptoTransform = Crypto.CreateAesEncryptor(passwordAesKey))
     {
         for (int j = 0; j < 16384; j++)
         {
             array2 = Crypto.EncryptAes(array2, cryptoTransform);
         }
     }
     byte[] array4 = new byte[8];
     Array.Copy(array2, 0, array4, 0, 4);
     Array.Copy(array2, 8, array4, 4, 4);
     return(array4.ToBase64());
 }
示例#6
0
        protected MegaAesCtrStream(Stream stream, long streamLength, Mode mode, byte[] fileKey, byte[] iv)
        {
            if (fileKey == null || fileKey.Length != 16)
            {
                throw new ArgumentException("Invalid fileKey");
            }

            if (iv == null || iv.Length != 8)
            {
                throw new ArgumentException("Invalid Iv");
            }

            _stream      = stream ?? throw new ArgumentNullException(nameof(stream));
            StreamLength = streamLength;
            _mode        = mode;
            FileKey      = fileKey;
            Iv           = iv;

            ChunksPositions       = GetChunksPositions(StreamLength).ToArray();
            _chunksPositionsCache = new HashSet <long>(ChunksPositions);

            _encryptor = Crypto.CreateAesEncryptor(FileKey);
        }