@@ -44,6 +44,7 @@ This file is part of the iText (R) project.
4444package com .itextpdf .kernel .pdf ;
4545
4646import java .io .Serializable ;
47+ import java .security .SecureRandom ;
4748import java .security .cert .Certificate ;
4849import java .util .Random ;
4950
@@ -72,22 +73,21 @@ public class EncryptionProperties implements Serializable {
7273 *
7374 * See {@link EncryptionConstants}.
7475 *
75- * @param userPassword the user password. Can be null or empty
76- * @param ownerPassword the owner password. Can be null or empty
77- * @param permissions the user permissions
76+ * @param userPassword the user password. Can be null or empty
77+ * @param ownerPassword the owner password. Can be null or empty
78+ * @param permissions the user permissions
7879 * @param encryptionAlgorithm the type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128,
79- * ENCRYPTION_AES128 or ENCRYPTION_AES256
80- * Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartext
80+ * ENCRYPTION_AES128 or ENCRYPTION_AES256
81+ * Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartext
8182 */
8283 public EncryptionProperties setStandardEncryption (byte [] userPassword , byte [] ownerPassword , int permissions , int encryptionAlgorithm ) {
8384 clearEncryption ();
8485 this .userPassword = userPassword ;
85- if (ownerPassword != null ) {
86+ if (ownerPassword != null ) {
8687 this .ownerPassword = ownerPassword ;
87- }else {
88- int r =(int ) (Integer .MAX_VALUE * Math .random ());
89- this .ownerPassword = Integer .toHexString (r ).getBytes ();
90-
88+ } else {
89+ this .ownerPassword = new byte [16 ];
90+ new SecureRandom ().nextBytes (this .ownerPassword );
9191 }
9292 this .standardEncryptPermissions = permissions ;
9393 this .encryptionAlgorithm = encryptionAlgorithm ;
@@ -106,10 +106,10 @@ public EncryptionProperties setStandardEncryption(byte[] userPassword, byte[] ow
106106 *
107107 * See {@link EncryptionConstants}.
108108 *
109- * @param certs the public certificates to be used for the encryption
110- * @param permissions the user permissions for each of the certificates
109+ * @param certs the public certificates to be used for the encryption
110+ * @param permissions the user permissions for each of the certificates
111111 * @param encryptionAlgorithm the type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128,
112- * ENCRYPTION_AES128 or ENCRYPTION_AES256.
112+ * ENCRYPTION_AES128 or ENCRYPTION_AES256.
113113 */
114114 public EncryptionProperties setPublicKeyEncryption (Certificate [] certs , int [] permissions , int encryptionAlgorithm ) {
115115 clearEncryption ();
0 commit comments