Ejemplo n.º 1
0
        /// <summary>
        /// Decrypts the given bytes using the entry encryption.
        /// </summary>
        public static byte[] Decrypt(byte[] entryBytes, string contentId, string passcode, MetaEntry meta)
        {
            var iv_key = Crypto.Sha256(
                meta.GetBytes()
                .Concat(Crypto.ComputeKeys(contentId, passcode, meta.KeyIndex))
                .ToArray());
            var tmp = new byte[entryBytes.Length];

            Crypto.AesCbcCfb128Decrypt(tmp, entryBytes, tmp.Length, iv_key.Skip(16).Take(16).ToArray(), iv_key.Take(16).ToArray());
            return(tmp);
        }
Ejemplo n.º 2
0
        private static byte[] Decrypt(byte[] entryBytes, byte[] keySeed, MetaEntry meta)
        {
            var iv_key = Crypto.Sha256(
                meta.GetBytes()
                .Concat(keySeed)
                .ToArray());
            var tmp = new byte[entryBytes.Length];

            Crypto.AesCbcCfb128Decrypt(tmp, entryBytes, tmp.Length, iv_key.Skip(16).Take(16).ToArray(), iv_key.Take(16).ToArray());
            return(tmp);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Decrypts the given entry using the entry encryption.
        /// Throws an exception if it can't be decrypted.
        /// </summary>
        public static byte[] Decrypt(byte[] entryBytes, Pkg pkg, MetaEntry meta)
        {
            if (meta.KeyIndex != 3)
            {
                throw new Exception("We only have the key for encryption key 3");
            }
            var iv_key = Crypto.Sha256(
                meta.GetBytes()
                .Concat(Crypto.RSA2048Decrypt(pkg.EntryKeys.Keys[3].key, RSAKeyset.PkgDerivedKey3Keyset))
                .ToArray());
            var tmp = new byte[entryBytes.Length];

            Crypto.AesCbcCfb128Decrypt(tmp, entryBytes, tmp.Length, iv_key.Skip(16).Take(16).ToArray(), iv_key.Take(16).ToArray());
            return(tmp);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Writes the entry in an encrypted form to the given stream.
        /// </summary>
        public void WriteEncrypted(Stream s, string contentId, string passcode)
        {
            var iv_key = Crypto.Sha256(
                meta.GetBytes()
                .Concat(Crypto.ComputeKeys(contentId, passcode, meta.KeyIndex))
                .ToArray());
            var tmp = new byte[Length];

            using (var ms = new MemoryStream(tmp))
            {
                Write(ms);
            }
            Crypto.AesCbcCfb128Encrypt(tmp, tmp, tmp.Length, iv_key.Skip(16).Take(16).ToArray(), iv_key.Take(16).ToArray());
            s.Write(tmp, 0, tmp.Length);
        }