equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
78 */ |
78 */ |
79 public PBEKeySpec(char[] password) { |
79 public PBEKeySpec(char[] password) { |
80 if ((password == null) || (password.length == 0)) { |
80 if ((password == null) || (password.length == 0)) { |
81 this.password = new char[0]; |
81 this.password = new char[0]; |
82 } else { |
82 } else { |
83 this.password = (char[])password.clone(); |
83 this.password = password.clone(); |
84 } |
84 } |
85 } |
85 } |
86 |
86 |
87 |
87 |
88 /** |
88 /** |
107 public PBEKeySpec(char[] password, byte[] salt, int iterationCount, |
107 public PBEKeySpec(char[] password, byte[] salt, int iterationCount, |
108 int keyLength) { |
108 int keyLength) { |
109 if ((password == null) || (password.length == 0)) { |
109 if ((password == null) || (password.length == 0)) { |
110 this.password = new char[0]; |
110 this.password = new char[0]; |
111 } else { |
111 } else { |
112 this.password = (char[])password.clone(); |
112 this.password = password.clone(); |
113 } |
113 } |
114 if (salt == null) { |
114 if (salt == null) { |
115 throw new NullPointerException("the salt parameter " + |
115 throw new NullPointerException("the salt parameter " + |
116 "must be non-null"); |
116 "must be non-null"); |
117 } else if (salt.length == 0) { |
117 } else if (salt.length == 0) { |
118 throw new IllegalArgumentException("the salt parameter " + |
118 throw new IllegalArgumentException("the salt parameter " + |
119 "must not be empty"); |
119 "must not be empty"); |
120 } else { |
120 } else { |
121 this.salt = (byte[]) salt.clone(); |
121 this.salt = salt.clone(); |
122 } |
122 } |
123 if (iterationCount<=0) { |
123 if (iterationCount<=0) { |
124 throw new IllegalArgumentException("invalid iterationCount value"); |
124 throw new IllegalArgumentException("invalid iterationCount value"); |
125 } |
125 } |
126 if (keyLength<=0) { |
126 if (keyLength<=0) { |
149 */ |
149 */ |
150 public PBEKeySpec(char[] password, byte[] salt, int iterationCount) { |
150 public PBEKeySpec(char[] password, byte[] salt, int iterationCount) { |
151 if ((password == null) || (password.length == 0)) { |
151 if ((password == null) || (password.length == 0)) { |
152 this.password = new char[0]; |
152 this.password = new char[0]; |
153 } else { |
153 } else { |
154 this.password = (char[])password.clone(); |
154 this.password = password.clone(); |
155 } |
155 } |
156 if (salt == null) { |
156 if (salt == null) { |
157 throw new NullPointerException("the salt parameter " + |
157 throw new NullPointerException("the salt parameter " + |
158 "must be non-null"); |
158 "must be non-null"); |
159 } else if (salt.length == 0) { |
159 } else if (salt.length == 0) { |
160 throw new IllegalArgumentException("the salt parameter " + |
160 throw new IllegalArgumentException("the salt parameter " + |
161 "must not be empty"); |
161 "must not be empty"); |
162 } else { |
162 } else { |
163 this.salt = (byte[]) salt.clone(); |
163 this.salt = salt.clone(); |
164 } |
164 } |
165 if (iterationCount<=0) { |
165 if (iterationCount<=0) { |
166 throw new IllegalArgumentException("invalid iterationCount value"); |
166 throw new IllegalArgumentException("invalid iterationCount value"); |
167 } |
167 } |
168 this.iterationCount = iterationCount; |
168 this.iterationCount = iterationCount; |
194 */ |
194 */ |
195 public final char[] getPassword() { |
195 public final char[] getPassword() { |
196 if (password == null) { |
196 if (password == null) { |
197 throw new IllegalStateException("password has been cleared"); |
197 throw new IllegalStateException("password has been cleared"); |
198 } |
198 } |
199 return (char[]) password.clone(); |
199 return password.clone(); |
200 } |
200 } |
201 |
201 |
202 /** |
202 /** |
203 * Returns a copy of the salt or null if not specified. |
203 * Returns a copy of the salt or null if not specified. |
204 * |
204 * |
208 * |
208 * |
209 * @return the salt. |
209 * @return the salt. |
210 */ |
210 */ |
211 public final byte[] getSalt() { |
211 public final byte[] getSalt() { |
212 if (salt != null) { |
212 if (salt != null) { |
213 return (byte[]) salt.clone(); |
213 return salt.clone(); |
214 } else { |
214 } else { |
215 return null; |
215 return null; |
216 } |
216 } |
217 } |
217 } |
218 |
218 |