当前位置: 首页>>代码示例>>Java>>正文


Java SecureRandom.getSeed方法代码示例

本文整理汇总了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;
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:28,代码来源:GenerateUniqueJobIdUtil.java

示例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);
    }
}
 
开发者ID:wolfSSL,项目名称:wolfcrypt-jni,代码行数:20,代码来源:WolfCryptRandomTest.java

示例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());
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:39,代码来源:JKS.java

示例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));
}
 
开发者ID:ampool,项目名称:monarch,代码行数:8,代码来源:InternalDataSerializerRandomizedJUnitTest.java


注:本文中的java.security.SecureRandom.getSeed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。