@@ -44,6 +44,7 @@ This file is part of the iText (R) project.
44
44
package com .itextpdf .kernel .pdf ;
45
45
46
46
import java .io .Serializable ;
47
+ import java .security .SecureRandom ;
47
48
import java .security .cert .Certificate ;
48
49
import java .util .Random ;
49
50
@@ -72,22 +73,21 @@ public class EncryptionProperties implements Serializable {
72
73
*
73
74
* See {@link EncryptionConstants}.
74
75
*
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
78
79
* @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
81
82
*/
82
83
public EncryptionProperties setStandardEncryption (byte [] userPassword , byte [] ownerPassword , int permissions , int encryptionAlgorithm ) {
83
84
clearEncryption ();
84
85
this .userPassword = userPassword ;
85
- if (ownerPassword != null ) {
86
+ if (ownerPassword != null ) {
86
87
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 );
91
91
}
92
92
this .standardEncryptPermissions = permissions ;
93
93
this .encryptionAlgorithm = encryptionAlgorithm ;
@@ -106,10 +106,10 @@ public EncryptionProperties setStandardEncryption(byte[] userPassword, byte[] ow
106
106
*
107
107
* See {@link EncryptionConstants}.
108
108
*
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
111
111
* @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.
113
113
*/
114
114
public EncryptionProperties setPublicKeyEncryption (Certificate [] certs , int [] permissions , int encryptionAlgorithm ) {
115
115
clearEncryption ();
0 commit comments