protected internal override void CheckPdfNumber(PdfNumber number) { if (Math.Abs(number.LongValue()) > GetMaxRealValue() && number.ToString().Contains(".")) { throw new PdfAConformanceException(PdfAConformanceException.RealNumberIsOutOfRange); } }
protected internal override void CheckPdfNumber(PdfNumber number) { if (Math.Abs(number.LongValue()) > GetMaxRealValue() && number.ToString().Contains(".")) { throw new PdfAConformanceException(PdfAConformanceException.REAL_NUMBER_IS_OUT_OF_RANGE); } }
protected internal override void CheckPdfNumber(PdfNumber number) { if (number.HasDecimalPoint()) { if (Math.Abs(number.LongValue()) > GetMaxRealValue()) { throw new PdfAConformanceException(PdfAConformanceException.REAL_NUMBER_IS_OUT_OF_RANGE); } } else { if (number.LongValue() > GetMaxIntegerValue() || number.LongValue() < GetMinIntegerValue()) { throw new PdfAConformanceException(PdfAConformanceException.INTEGER_NUMBER_IS_OUT_OF_RANGE); } } }
private void InitKeyAndReadDictionary(PdfDictionary encryptionDictionary, byte[] password, byte[] documentId , bool encryptMetadata) { byte[] uValue = GetIsoBytes(encryptionDictionary.GetAsString(PdfName.U)); byte[] oValue = GetIsoBytes(encryptionDictionary.GetAsString(PdfName.O)); PdfNumber pValue = (PdfNumber)encryptionDictionary.Get(PdfName.P); this.permissions = pValue.LongValue(); this.documentId = documentId; keyLength = GetKeyLength(encryptionDictionary); byte[] paddedPassword = PadPassword(password); CheckPassword(encryptMetadata, uValue, oValue, paddedPassword); }
private void InitKeyAndReadDictionary(PdfDictionary encryptionDictionary, byte[] password) { try { if (password == null) { password = new byte[0]; } else { if (password.Length > 127) { password = JavaUtil.ArraysCopyOf(password, 127); } } isPdf2 = encryptionDictionary.GetAsNumber(PdfName.R).GetValue() == 6; byte[] oValue = GetIsoBytes(encryptionDictionary.GetAsString(PdfName.O)); byte[] uValue = GetIsoBytes(encryptionDictionary.GetAsString(PdfName.U)); byte[] oeValue = GetIsoBytes(encryptionDictionary.GetAsString(PdfName.OE)); byte[] ueValue = GetIsoBytes(encryptionDictionary.GetAsString(PdfName.UE)); byte[] perms = GetIsoBytes(encryptionDictionary.GetAsString(PdfName.Perms)); PdfNumber pValue = (PdfNumber)encryptionDictionary.Get(PdfName.P); this.permissions = pValue.LongValue(); byte[] hash; hash = ComputeHash(password, oValue, VALIDATION_SALT_OFFSET, SALT_LENGTH, uValue); usedOwnerPassword = CompareArray(hash, oValue, 32); if (usedOwnerPassword) { hash = ComputeHash(password, oValue, KEY_SALT_OFFSET, SALT_LENGTH, uValue); AESCipherCBCnoPad ac = new AESCipherCBCnoPad(false, hash); nextObjectKey = ac.ProcessBlock(oeValue, 0, oeValue.Length); } else { hash = ComputeHash(password, uValue, VALIDATION_SALT_OFFSET, SALT_LENGTH); if (!CompareArray(hash, uValue, 32)) { throw new BadPasswordException(PdfException.BadUserPassword); } hash = ComputeHash(password, uValue, KEY_SALT_OFFSET, SALT_LENGTH); AESCipherCBCnoPad ac = new AESCipherCBCnoPad(false, hash); nextObjectKey = ac.ProcessBlock(ueValue, 0, ueValue.Length); } nextObjectKeySize = 32; AESCipherCBCnoPad ac_1 = new AESCipherCBCnoPad(false, nextObjectKey); byte[] decPerms = ac_1.ProcessBlock(perms, 0, perms.Length); if (decPerms[9] != (byte)'a' || decPerms[10] != (byte)'d' || decPerms[11] != (byte)'b') { throw new BadPasswordException(PdfException.BadUserPassword); } int permissionsDecoded = (decPerms[0] & 0xff) | ((decPerms[1] & 0xff) << 8) | ((decPerms[2] & 0xff) << 16) | ((decPerms[3] & 0xff) << 24); bool encryptMetadata = decPerms[8] == (byte)'T'; bool?encryptMetadataEntry = encryptionDictionary.GetAsBool(PdfName.EncryptMetadata); if (permissionsDecoded != permissions || encryptMetadataEntry != null && encryptMetadata != encryptMetadataEntry ) { ILog logger = LogManager.GetLogger(typeof(iText.Kernel.Crypto.Securityhandler.StandardHandlerUsingAes256)); logger.Error(iText.IO.LogMessageConstant.ENCRYPTION_ENTRIES_P_AND_ENCRYPT_METADATA_NOT_CORRESPOND_PERMS_ENTRY ); } this.permissions = permissionsDecoded; this.encryptMetadata = encryptMetadata; } catch (BadPasswordException ex) { throw; } catch (Exception ex) { throw new PdfException(PdfException.PdfEncryption, ex); } }
private void InitKeyAndReadDictionary(PdfDictionary encryptionDictionary, byte[] password) { try { if (password == null) { password = new byte[0]; } byte[] oValue = GetIsoBytes(encryptionDictionary.GetAsString(PdfName.O)); byte[] uValue = GetIsoBytes(encryptionDictionary.GetAsString(PdfName.U)); byte[] oeValue = GetIsoBytes(encryptionDictionary.GetAsString(PdfName.OE)); byte[] ueValue = GetIsoBytes(encryptionDictionary.GetAsString(PdfName.UE)); byte[] perms = GetIsoBytes(encryptionDictionary.GetAsString(PdfName.Perms)); PdfNumber pValue = (PdfNumber)encryptionDictionary.Get(PdfName.P); this.permissions = pValue.LongValue(); IDigest md = Org.BouncyCastle.Security.DigestUtilities.GetDigest("SHA-256"); md.Update(password, 0, Math.Min(password.Length, 127)); md.Update(oValue, VALIDATION_SALT_OFFSET, SALT_LENGTH); md.Update(uValue, 0, OU_LENGTH); byte[] hash = md.Digest(); usedOwnerPassword = CompareArray(hash, oValue, 32); if (usedOwnerPassword) { md.Update(password, 0, Math.Min(password.Length, 127)); md.Update(oValue, KEY_SALT_OFFSET, SALT_LENGTH); md.Update(uValue, 0, OU_LENGTH); hash = md.Digest(); AESCipherCBCnoPad ac = new AESCipherCBCnoPad(false, hash); nextObjectKey = ac.ProcessBlock(oeValue, 0, oeValue.Length); } else { md.Update(password, 0, Math.Min(password.Length, 127)); md.Update(uValue, VALIDATION_SALT_OFFSET, SALT_LENGTH); hash = md.Digest(); if (!CompareArray(hash, uValue, 32)) { throw new BadPasswordException(PdfException.BadUserPassword); } md.Update(password, 0, Math.Min(password.Length, 127)); md.Update(uValue, KEY_SALT_OFFSET, SALT_LENGTH); hash = md.Digest(); AESCipherCBCnoPad ac = new AESCipherCBCnoPad(false, hash); nextObjectKey = ac.ProcessBlock(ueValue, 0, ueValue.Length); } nextObjectKeySize = 32; AESCipherCBCnoPad ac_1 = new AESCipherCBCnoPad(false, nextObjectKey); byte[] decPerms = ac_1.ProcessBlock(perms, 0, perms.Length); if (decPerms[9] != (byte)'a' || decPerms[10] != (byte)'d' || decPerms[11] != (byte)'b') { throw new BadPasswordException(PdfException.BadUserPassword); } permissions = (decPerms[0] & 0xff) | ((decPerms[1] & 0xff) << 8) | ((decPerms[2] & 0xff) << 16) | ((decPerms [2] & 0xff) << 24); encryptMetadata = decPerms[8] == (byte)'T'; } catch (BadPasswordException ex) { throw; } catch (Exception ex) { throw new PdfException(PdfException.PdfEncryption, ex); } }