Example #1
0
        private static TStandardEncryptionVerifier ReadStandardVerifier(byte[] Verifier)
        {
            TStandardEncryptionVerifier Result = new TStandardEncryptionVerifier();

            Result.EncryptedVerifier = new byte[16];
            Array.Copy(Verifier, 20, Result.EncryptedVerifier, 0, Result.EncryptedVerifier.Length);

            Result.VerifierHashSizeBytes = (int)BitOps.GetCardinal(Verifier, 20 + 16) / 8;
            Result.EncryptedVerifierHash = new byte[32];
            Array.Copy(Verifier, 20 + 16 + 4, Result.EncryptedVerifierHash, 0, Result.EncryptedVerifierHash.Length);

            return(Result);
        }
Example #2
0
        private static Stream ReadStandardEncryptionInfo(TOle2File DataStream, TEncryptionData Encryption)
        {
            byte[] RecordHeaderLen = new byte[4];
            DataStream.Read(RecordHeaderLen, RecordHeaderLen.Length);

            long EncryptionHeaderSize = BitOps.GetCardinal(RecordHeaderLen, 0);

            byte[] EncryptionHeader = new byte[EncryptionHeaderSize];
            DataStream.Read(EncryptionHeader, EncryptionHeader.Length);
            long AlgId   = BitOps.GetCardinal(EncryptionHeader, 8);
            long KeyBits = BitOps.GetCardinal(EncryptionHeader, 16);

            TEncryptionParameters EncParams = TEncryptionParameters.CreateStandard(GetStandardEncAlg(AlgId));

            byte[] VerifierBytes = new byte[DataStream.Length - DataStream.Position];
            DataStream.Read(VerifierBytes, VerifierBytes.Length);
            TStandardEncryptionVerifier Verifier = ReadStandardVerifier(VerifierBytes);
            TEncryptionKey Key = new TStandardEncryptionKey(ReadStandardSalt(VerifierBytes), (int)KeyBits / 8);

            CheckPassword(Encryption, Verifier, EncParams, Key);

            return(DecryptStream(DataStream, EncParams, Key));
        }