當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。