Esempio n. 1
0
 public void Reset()
 {
     if (_revision < 5)
     {
         _ownerHash     = calculateOwnerHash(_ownerPassword, _userPassword, false);
         _userHash      = calculateUserHash(_userPassword);
         _encryptionKey = computeEncryptionKey(_userPassword, _length);
         if (_revision == 4)
         {
             _stmF = CryptFilter.AESV2;
             _strF = CryptFilter.AESV2;
         }
     }
     else
     {
         _userHash      = computeUserHash(_userPassword);
         _ownerHash     = computeOwnerHash(_ownerPassword, _userHash);
         _encryptionKey = new byte[32];
         Random rnd = new Random();
         rnd.NextBytes(_encryptionKey);
         _ue    = computeUE(_encryptionKey, _userPassword);
         _oe    = computeOE(_encryptionKey, _ownerPassword, _userHash);
         _perms = computePerms();
         _stmF  = CryptFilter.AESV3;
         _strF  = CryptFilter.AESV3;
     }
 }
Esempio n. 2
0
        private void readCFM(PDFDictionary CF, string key, out CryptFilter filter)
        {
            filter = CryptFilter.Identity;
            if (CF == null)
            {
                return;
            }

            PDFDictionary StdCF = CF[key] as PDFDictionary;

            if (StdCF != null)
            {
                PDFName cfm = StdCF["CFM"] as PDFName;
                if (cfm == null)
                {
                    return;
                }

                switch (cfm.GetValue())
                {
                case "V2":
                    filter = CryptFilter.V2;
                    break;

                case "AESV2":
                    filter = CryptFilter.AESV2;
                    break;

                case "AESV3":
                    filter = CryptFilter.AESV3;
                    break;

                default:
                    filter = CryptFilter.Identity;
                    break;
                }
            }
        }
Esempio n. 3
0
        private void readCryptFilters(PDFDictionary dictionary)
        {
            PDFName stmf = dictionary["StmF"] as PDFName;
            PDFName strf = dictionary["StrF"] as PDFName;

            if (stmf == null)
            {
                _stmF = CryptFilter.Identity;
            }
            else
            {
                readCFM(dictionary["CF"] as PDFDictionary, stmf.GetValue(), out _stmF);
            }

            if (strf == null)
            {
                _strF = CryptFilter.Identity;
            }
            else
            {
                readCFM(dictionary["CF"] as PDFDictionary, strf.GetValue(), out _strF);
            }
        }