本文整理汇总了Java中java.security.SecureRandom.getSeed方法的典型用法代码示例。如果您正苦于以下问题:Java SecureRandom.getSeed方法的具体用法?Java SecureRandom.getSeed怎么用?Java SecureRandom.getSeed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.SecureRandom
的用法示例。
在下文中一共展示了SecureRandom.getSeed方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateUniqueJobId
import java.security.SecureRandom; //导入方法依赖的package包/类
/**
* Generates Unique Job Id.
*
* @return {@link String}
*/
public String generateUniqueJobId() throws NoSuchAlgorithmException {
String uniqueJobId = "";
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
int number = 0;
for (int i = 0; i < 20; i++) {
number = random.nextInt(21);
}
byte[] secureRandom = random.getSeed(number);
long milliSeconds = System.currentTimeMillis();
String timeStampLong = Long.toString(milliSeconds);
/*
* String timeStamp = new
* SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
* this.uniqueJobId=jobId.concat(""+secureRandom.hashCode()).concat(
* JOB_ID_STRING_SEPARATOR+timeStampLong) + JOB_ID_STRING_SEPARATOR +
* timeStamp;
*/
uniqueJobId = "Job_".concat("" + secureRandom.hashCode()).concat("_" + timeStampLong);
return uniqueJobId;
}
示例2: testGetSeed
import java.security.SecureRandom; //导入方法依赖的package包/类
@Test
public void testGetSeed()
throws NoSuchProviderException, NoSuchAlgorithmException {
byte[] valuesA = new byte[128];
byte[] valuesB = new byte[128];
SecureRandom rand = SecureRandom.getInstance("HashDRBG", "wolfJCE");
valuesA = rand.getSeed(valuesA.length);
for (int i = 0; i < 10; i++) {
valuesB = rand.getSeed(valuesB.length);
if(Arrays.equals(valuesA, valuesB))
fail("SecureRandom generated two equal consecutive arrays");
valuesA = Arrays.copyOf(valuesB, valuesB.length);
}
}
示例3: encryptKey
import java.security.SecureRandom; //导入方法依赖的package包/类
private static byte[] encryptKey(Key key, byte[] passwd)
throws KeyStoreException
{
try
{
MessageDigest sha = MessageDigest.getInstance("SHA1");
SecureRandom rand = SecureRandom.getInstance("SHA1PRNG");
byte[] k = key.getEncoded();
byte[] encrypted = new byte[k.length + 40];
byte[] keystream = rand.getSeed(20);
System.arraycopy(keystream, 0, encrypted, 0, 20);
int count = 0;
while (count < k.length)
{
sha.reset();
sha.update(passwd);
sha.update(keystream);
sha.digest(keystream, 0, keystream.length);
for (int i = 0; i < keystream.length && count < k.length; i++)
{
encrypted[count+20] = (byte) (keystream[i] ^ k[count]);
count++;
}
}
sha.reset();
sha.update(passwd);
sha.update(k);
sha.digest(encrypted, encrypted.length - 20, 20);
// 1.3.6.1.4.1.42.2.17.1.1 is Sun's private OID for this
// encryption algorithm.
return new EncryptedPrivateKeyInfo("1.3.6.1.4.1.42.2.17.1.1",
encrypted).getEncoded();
}
catch (Exception x)
{
throw new KeyStoreException(x.getMessage());
}
}
示例4: RandomStringGenerator
import java.security.SecureRandom; //导入方法依赖的package包/类
/**
* Generate and return a random string made up of a series of Unicode codepoints (integers).
* This can be any series of codepoints, even unreserved ones.
*/
public RandomStringGenerator() {
this(SecureRandom.getSeed(SEED_BYTES));
}