87 |
*/ |
*/ |
88 |
public SecureRandom() |
public SecureRandom() |
89 |
{ |
{ |
90 |
Provider p[] = Security.getProviders(); |
Provider[] p = Security.getProviders(); |
91 |
|
|
92 |
//Format of Key: SecureRandom.algname |
//Format of Key: SecureRandom.algname |
93 |
String key; |
String key; |
112 |
provider = p[i]; |
provider = p[i]; |
113 |
return; |
return; |
114 |
} |
} |
115 |
catch (Throwable ignore) { } |
catch (Throwable t) |
116 |
|
{ |
117 |
|
// Ignore. |
118 |
|
} |
119 |
} |
} |
120 |
} |
} |
121 |
} |
} |
170 |
* @throws NoSuchAlgorithmException If no installed provider implements |
* @throws NoSuchAlgorithmException If no installed provider implements |
171 |
* the given algorithm. |
* the given algorithm. |
172 |
*/ |
*/ |
173 |
public static SecureRandom getInstance(String algorithm) throws |
public static SecureRandom getInstance(String algorithm) |
174 |
NoSuchAlgorithmException |
throws NoSuchAlgorithmException |
175 |
{ |
{ |
176 |
Provider p[] = Security.getProviders(); |
Provider[] p = Security.getProviders(); |
177 |
|
|
178 |
for (int i = 0; i < p.length; i++) |
for (int i = 0; i < p.length; i++) |
179 |
{ |
{ |
180 |
try |
try |
181 |
{ |
{ |
182 |
return getInstance(algorithm, p[i]); |
return getInstance(algorithm, p[i]); |
183 |
} |
} |
184 |
catch (NoSuchAlgorithmException ignored) |
catch (NoSuchAlgorithmException e) |
185 |
{ |
{ |
186 |
|
// Ignore. |
187 |
} |
} |
188 |
} |
} |
189 |
|
|
289 |
// Therefore we test. |
// Therefore we test. |
290 |
if (secureRandomSpi != null) |
if (secureRandomSpi != null) |
291 |
{ |
{ |
292 |
byte tmp[] = { (byte) (0xff & (seed >> 56)), |
byte[] tmp = { (byte) (0xff & (seed >> 56)), |
293 |
(byte) (0xff & (seed >> 48)), |
(byte) (0xff & (seed >> 48)), |
294 |
(byte) (0xff & (seed >> 40)), |
(byte) (0xff & (seed >> 40)), |
295 |
(byte) (0xff & (seed >> 32)), |
(byte) (0xff & (seed >> 32)), |
329 |
if (numBits == 0) |
if (numBits == 0) |
330 |
return 0; |
return 0; |
331 |
|
|
332 |
byte tmp[] = new byte[numBits / 8 + (1 * (numBits % 8))]; |
byte[] tmp = new byte[numBits / 8 + (1 * (numBits % 8))]; |
333 |
|
|
334 |
secureRandomSpi.engineNextBytes(tmp); |
secureRandomSpi.engineNextBytes(tmp); |
335 |
randomBytesUsed += tmp.length; |
randomBytesUsed += tmp.length; |
354 |
*/ |
*/ |
355 |
public static byte[] getSeed(int numBytes) |
public static byte[] getSeed(int numBytes) |
356 |
{ |
{ |
357 |
byte tmp[] = new byte[numBytes]; |
byte[] tmp = new byte[numBytes]; |
358 |
|
|
359 |
new Random().nextBytes(tmp); |
new Random().nextBytes(tmp); |
360 |
return tmp; |
return tmp; |