equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2005, 2013, 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 |
31 import java.nio.charset.Charset; |
31 import java.nio.charset.Charset; |
32 import java.util.Arrays; |
32 import java.util.Arrays; |
33 import java.security.KeyRep; |
33 import java.security.KeyRep; |
34 import java.security.GeneralSecurityException; |
34 import java.security.GeneralSecurityException; |
35 import java.security.NoSuchAlgorithmException; |
35 import java.security.NoSuchAlgorithmException; |
36 import java.security.NoSuchProviderException; |
|
37 import java.security.spec.InvalidKeySpecException; |
36 import java.security.spec.InvalidKeySpecException; |
38 import javax.crypto.Mac; |
37 import javax.crypto.Mac; |
39 import javax.crypto.SecretKey; |
38 import javax.crypto.SecretKey; |
40 import javax.crypto.spec.PBEKeySpec; |
39 import javax.crypto.spec.PBEKeySpec; |
41 |
40 |
104 throw new InvalidKeySpecException("Key length not found"); |
103 throw new InvalidKeySpecException("Key length not found"); |
105 } else if (keyLength == 0) { |
104 } else if (keyLength == 0) { |
106 throw new InvalidKeySpecException("Key length is negative"); |
105 throw new InvalidKeySpecException("Key length is negative"); |
107 } |
106 } |
108 try { |
107 try { |
109 this.prf = Mac.getInstance(prfAlgo, "SunJCE"); |
108 this.prf = Mac.getInstance(prfAlgo, SunJCE.getInstance()); |
110 } catch (NoSuchAlgorithmException nsae) { |
109 } catch (NoSuchAlgorithmException nsae) { |
111 // not gonna happen; re-throw just in case |
110 // not gonna happen; re-throw just in case |
112 InvalidKeySpecException ike = new InvalidKeySpecException(); |
111 InvalidKeySpecException ike = new InvalidKeySpecException(); |
113 ike.initCause(nsae); |
112 ike.initCause(nsae); |
114 throw ike; |
|
115 } catch (NoSuchProviderException nspe) { |
|
116 // Again, not gonna happen; re-throw just in case |
|
117 InvalidKeySpecException ike = new InvalidKeySpecException(); |
|
118 ike.initCause(nspe); |
|
119 throw ike; |
113 throw ike; |
120 } |
114 } |
121 this.key = deriveKey(prf, passwdBytes, salt, iterCount, keyLength); |
115 this.key = deriveKey(prf, passwdBytes, salt, iterCount, keyLength); |
122 } |
116 } |
123 |
117 |