• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java IRandom类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中gnu.java.security.prng.IRandom的典型用法代码示例。如果您正苦于以下问题:Java IRandom类的具体用法?Java IRandom怎么用?Java IRandom使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

IRandom类属于gnu.java.security.prng包,在下文中一共展示了IRandom类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getInstance

点赞 3

import gnu.java.security.prng.IRandom; //导入依赖的package包/类
public static final PRNG getInstance()
{
  IRandom delegate = new MDGenerator();
  try
    {
      HashMap map = new HashMap();
      // initialise it with a seed
      long t = System.currentTimeMillis();
      byte[] seed = new byte[] {
          (byte)(t >>> 56), (byte)(t >>> 48),
          (byte)(t >>> 40), (byte)(t >>> 32),
          (byte)(t >>> 24), (byte)(t >>> 16),
          (byte)(t >>>  8), (byte) t };
      map.put(MDGenerator.SEEED, seed);
      delegate.init(map); // default is to use SHA-1 hash
    }
  catch (Exception x)
    {
      throw new ExceptionInInitializerError(x);
    }
  return new PRNG(delegate);
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:23,
代码来源:PRNG.java

示例2: update

点赞 3

import gnu.java.security.prng.IRandom; //导入依赖的package包/类
/**
 * Similar to the same method with one argument, but uses the designated
 * random number generator to compute needed keying material.
 *
 * @param b the byte to process.
 * @param prng the source of randomness to use.
 */
public void update(byte b, IRandom prng)
{
  Mi <<= 8; // update message buffer
  Mi |= b & 0xFF;
  msgLength++; // update message length (bytes)
  if (msgLength % 2 == 0) // got a full word
    {
      msgWords++; // update message words counter
      System.arraycopy(Ki, 1, Ki, 0, tagWords - 1); // 1. shift Ki up by 1
      Ki[tagWords - 1] = getNextKeyWord(prng); // 2. fill last box of Ki
      long t; // temp var to allow working in modulo 2^32
      for (int i = 0; i < tagWords; i++) // 3. update context
        {
          t = context[i] & 0xFFFFFFFFL;
          t += Ki[i] * Mi;
          context[i] = (int) t;
        }
      Mi = 0; // reset message buffer
    }
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:28,
代码来源:TMMH16.java

示例3: update

点赞 3

import gnu.java.security.prng.IRandom; //导入依赖的package包/类
/**
 * Similar to the same method with one argument, but uses the designated
 * random number generator to compute needed keying material.
 * 
 * @param b the byte to process.
 * @param prng the source of randomness to use.
 */
public void update(byte b, IRandom prng)
{
  Mi <<= 8; // update message buffer
  Mi |= b & 0xFF;
  msgLength++; // update message length (bytes)
  if (msgLength % 2 == 0) // got a full word
    {
      msgWords++; // update message words counter
      System.arraycopy(Ki, 1, Ki, 0, tagWords - 1); // 1. shift Ki up by 1
      Ki[tagWords - 1] = getNextKeyWord(prng); // 2. fill last box of Ki
      long t; // temp var to allow working in modulo 2^32
      for (int i = 0; i < tagWords; i++) // 3. update context
        {
          t = context[i] & 0xFFFFFFFFL;
          t += Ki[i] * Mi;
          context[i] = (int) t;
        }
      Mi = 0; // reset message buffer
    }
}
 

开发者ID:nmldiegues,
项目名称:jvm-stm,
代码行数:28,
代码来源:TMMH16.java

示例4: setup

点赞 2

import gnu.java.security.prng.IRandom; //导入依赖的package包/类
private void setup(Map attributes)
{
  init();
  // do we have a Random or SecureRandom, or should we use our own?
  Object obj = attributes.get(SOURCE_OF_RANDOMNESS);
  if (obj instanceof Random)
    rnd = (Random) obj;
  else if (obj instanceof IRandom)
    irnd = (IRandom) obj;
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:11,
代码来源:BaseSignature.java

示例5: sign

点赞 2

import gnu.java.security.prng.IRandom; //导入依赖的package包/类
public static final BigInteger[] sign(final DSAPrivateKey k, final byte[] h,
                                      IRandom irnd)
{
  final DSSSignature sig = new DSSSignature();
  final Map attributes = new HashMap();
  attributes.put(ISignature.SIGNER_KEY, k);
  if (irnd != null)
    attributes.put(ISignature.SOURCE_OF_RANDOMNESS, irnd);

  sig.setupSign(attributes);
  return sig.computeRS(h);
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:13,
代码来源:DSSSignature.java

示例6: PRNG

点赞 2

import gnu.java.security.prng.IRandom; //导入依赖的package包/类
/**
 * Private constructor to enforce using the Factory method.
 *
 * @param delegate the undelying {@link IRandom} object used.
 */
private PRNG(IRandom delegate)
{
  super();

  this.delegate = delegate;
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:12,
代码来源:PRNG.java

示例7: getInstance

点赞 2

import gnu.java.security.prng.IRandom; //导入依赖的package包/类
/**
 * Returns an instance of a padding algorithm given its name.
 *
 * @param prng the case-insensitive name of the PRNG.
 * @return an instance of the pseudo-random number generator.
 * @exception InternalError if the implementation does not pass its self-
 *              test.
 */
public static IRandom getInstance(String prng)
{
  if (prng == null)
    return null;
  prng = prng.trim();
  IRandom result = null;
  if (prng.equalsIgnoreCase(ARCFOUR_PRNG) || prng.equalsIgnoreCase(RC4_PRNG))
    result = new ARCFour();
  else if (prng.equalsIgnoreCase(ICM_PRNG))
    result = new ICMGenerator();
  else if (prng.equalsIgnoreCase(UMAC_PRNG))
    result = new UMacGenerator();
  else if (prng.toLowerCase().startsWith(PBKDF2_PRNG_PREFIX))
    {
      String macName = prng.substring(PBKDF2_PRNG_PREFIX.length());
      IMac mac = MacFactory.getInstance(macName);
      if (mac == null)
        return null;
      result = new PBKDF2(mac);
    }

  if (result != null)
    return result;

  return gnu.java.security.prng.PRNGFactory.getInstance(prng);
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:35,
代码来源:PRNGFactory.java

示例8: engineGenerateSecret

点赞 2

import gnu.java.security.prng.IRandom; //导入依赖的package包/类
protected SecretKey engineGenerateSecret(KeySpec spec)
    throws InvalidKeySpecException
{
  if (! (spec instanceof PBEKeySpec))
    throw new InvalidKeySpecException("not a PBEKeySpec");
  IRandom kdf = PRNGFactory.getInstance("PBKDF2-" + macName);
  HashMap attr = new HashMap();
  attr.put(IPBE.PASSWORD, ((PBEKeySpec) spec).getPassword());
  byte[] salt = ((PBEKeySpec) spec).getSalt();
  if (salt == null)
    salt = new byte[0];
  attr.put(IPBE.SALT, salt);
  int ic = ((PBEKeySpec) spec).getIterationCount();
  if (ic <= 0)
    ic = DEFAULT_ITERATION_COUNT;
  attr.put(IPBE.ITERATION_COUNT, Integer.valueOf(ic));
  kdf.init(attr);
  int len = ((PBEKeySpec) spec).getKeyLength();
  if (len <= 0)
    len = DEFAULT_KEY_LEN;
  byte[] dk = new byte[len];
  try
    {
      kdf.nextBytes(dk, 0, len);
    }
  catch (LimitReachedException lre)
    {
      throw new IllegalArgumentException(lre.toString());
    }
  return new SecretKeySpec(dk, "PBKDF2");
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:32,
代码来源:PBKDF2SecretKeyFactory.java

示例9: genkey

点赞 2

import gnu.java.security.prng.IRandom; //导入依赖的package包/类
private SecretKeySpec genkey(PBEKey key) throws InvalidKeyException
{
  IRandom kdf = PRNGFactory.getInstance("PBKDF2-" + macName);
  if (kdf == null)
    throw new IllegalArgumentException("no such KDF: PBKDF2-" + macName);
  HashMap attrib = new HashMap();
  attrib.put(IPBE.ITERATION_COUNT, Integer.valueOf(key.getIterationCount()));
  attrib.put(IPBE.PASSWORD, key.getPassword());
  attrib.put(IPBE.SALT, key.getSalt());
  try
    {
      kdf.init(attrib);
    }
  catch (IllegalArgumentException iae)
    {
      throw new InvalidKeyException(iae.toString());
    }
  byte[] dk = new byte[mode.defaultKeySize()];
  try
    {
      kdf.nextBytes(dk, 0, dk.length);
    }
  catch (LimitReachedException shouldNotHappen)
    {
      throw new Error(String.valueOf(shouldNotHappen));
    }
  return new SecretKeySpec(dk, cipher.name());
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:29,
代码来源:PBES2.java

示例10: clone

点赞 2

import gnu.java.security.prng.IRandom; //导入依赖的package包/类
public Object clone() throws CloneNotSupportedException
{
  TMMH16 result = (TMMH16) super.clone();
  if (this.keystream != null)
    result.keystream = (IRandom) this.keystream.clone();
  if (this.prefix != null)
    result.prefix = (byte[]) this.prefix.clone();
  if (this.context != null)
    result.context = (int[]) this.context.clone();
  if (this.K0 != null)
    result.K0 = (int[]) this.K0.clone();
  if (this.Ki != null)
    result.Ki = (int[]) this.Ki.clone();
  return result;
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:16,
代码来源:TMMH16.java

示例11: digest

点赞 2

import gnu.java.security.prng.IRandom; //导入依赖的package包/类
/**
 * Similar to the same method with no arguments, but uses the designated
 * random number generator to compute needed keying material.
 *
 * @param prng the source of randomness to use.
 * @return the final result of the algorithm.
 */
public byte[] digest(IRandom prng)
{
  doFinalRound(prng);
  byte[] result = new byte[tagWords * 2];
  for (int i = 0, j = 0; i < tagWords; i++)
    {
      result[j] = (byte)((context[i] >>> 8) ^ prefix[j]);
      j++;
      result[j] = (byte)(context[i] ^ prefix[j]);
      j++;
    }
  reset();
  return result;
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:22,
代码来源:TMMH16.java

示例12: getNextKeyWord

点赞 2

import gnu.java.security.prng.IRandom; //导入依赖的package包/类
private int getNextKeyWord(IRandom prng)
{
  int result = 0;
  try
    {
      result = (prng.nextByte() & 0xFF) << 8 | (prng.nextByte() & 0xFF);
    }
  catch (LimitReachedException x)
    {
      throw new RuntimeException(String.valueOf(x));
    }
  keyWords++; // update key words counter
  return result;
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:15,
代码来源:TMMH16.java

示例13: doFinalRound

点赞 2

import gnu.java.security.prng.IRandom; //导入依赖的package包/类
private void doFinalRound(IRandom prng)
{
  long limit = msgLength; // formula works on real message length
  while (msgLength % 2 != 0)
    update((byte) 0x00, prng);
  long t;
  for (int i = 0; i < tagWords; i++)
    {
      t = context[i] & 0xFFFFFFFFL;
      t += K0[i] * limit;
      t %= P;
      context[i] = (int) t;
    }
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:15,
代码来源:TMMH16.java

示例14: PRNG

点赞 2

import gnu.java.security.prng.IRandom; //导入依赖的package包/类
/**
 * Private constructor to enforce using the Factory method.
 * 
 * @param delegate the undelying {@link IRandom} object used.
 */
private PRNG(IRandom delegate)
{
  super();

  this.delegate = delegate;
}
 

开发者ID:nmldiegues,
项目名称:jvm-stm,
代码行数:12,
代码来源:PRNG.java

示例15: getInstance

点赞 2

import gnu.java.security.prng.IRandom; //导入依赖的package包/类
/**
 * Returns an instance of a padding algorithm given its name.
 * 
 * @param prng the case-insensitive name of the PRNG.
 * @return an instance of the pseudo-random number generator.
 * @exception InternalError if the implementation does not pass its self-
 *              test.
 */
public static IRandom getInstance(String prng)
{
  if (prng == null)
    return null;
  prng = prng.trim();
  IRandom result = null;
  if (prng.equalsIgnoreCase(ARCFOUR_PRNG) || prng.equalsIgnoreCase(RC4_PRNG))
    result = new ARCFour();
  else if (prng.equalsIgnoreCase(ICM_PRNG))
    result = new ICMGenerator();
  else if (prng.equalsIgnoreCase(UMAC_PRNG))
    result = new UMacGenerator();
  else if (prng.toLowerCase().startsWith(PBKDF2_PRNG_PREFIX))
    {
      String macName = prng.substring(PBKDF2_PRNG_PREFIX.length());
      IMac mac = MacFactory.getInstance(macName);
      if (mac == null)
        return null;
      result = new PBKDF2(mac);
    }

  if (result != null)
    return result;

  return gnu.java.security.prng.PRNGFactory.getInstance(prng);
}
 

开发者ID:nmldiegues,
项目名称:jvm-stm,
代码行数:35,
代码来源:PRNGFactory.java

示例16: digest

点赞 2

import gnu.java.security.prng.IRandom; //导入依赖的package包/类
/**
 * Similar to the same method with no arguments, but uses the designated
 * random number generator to compute needed keying material.
 * 
 * @param prng the source of randomness to use.
 * @return the final result of the algorithm.
 */
public byte[] digest(IRandom prng)
{
  doFinalRound(prng);
  byte[] result = new byte[tagWords * 2];
  for (int i = 0, j = 0; i < tagWords; i++)
    {
      result[j] = (byte)((context[i] >>> 8) ^ prefix[j]);
      j++;
      result[j] = (byte)(context[i] ^ prefix[j]);
      j++;
    }
  reset();
  return result;
}
 

开发者ID:nmldiegues,
项目名称:jvm-stm,
代码行数:22,
代码来源:TMMH16.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)