org.spongycastle.crypto.macs.HMac.init()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(130)

本文整理了Java中org.spongycastle.crypto.macs.HMac.init()方法的一些代码示例,展示了HMac.init()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HMac.init()方法的具体详情如下:
包路径:org.spongycastle.crypto.macs.HMac
类名称:HMac
方法名:init

HMac.init介绍

暂无

代码示例

代码示例来源:origin: com.madgag.spongycastle/bctls-jdk15on

public void setKey(byte[] key, int keyOff, int keyLen)
{
  hmac.init(new KeyParameter(key, keyOff, keyLen));
}

代码示例来源:origin: com.google/bitcoinj

static HMac createHmacSha512Digest(byte[] key) {
  SHA512Digest digest = new SHA512Digest();
  HMac hMac = new HMac(digest);
  hMac.init(new KeyParameter(key));
  return hMac;
}

代码示例来源:origin: fr.acinq/bitcoinj-core

static HMac createHmacSha512Digest(byte[] key) {
  SHA512Digest digest = new SHA512Digest();
  HMac hMac = new HMac(digest);
  hMac.init(new KeyParameter(key));
  return hMac;
}

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

static HMac createHmacSha512Digest(byte[] key) {
  SHA512Digest digest = new SHA512Digest();
  HMac hMac = new HMac(digest);
  hMac.init(new KeyParameter(key));
  return hMac;
}

代码示例来源:origin: greenaddress/GreenBits

static HMac createHmacSha512Digest(byte[] key) {
  SHA512Digest digest = new SHA512Digest();
  HMac hMac = new HMac(digest);
  hMac.init(new KeyParameter(key));
  return hMac;
}

代码示例来源:origin: HashEngineering/dashj

static HMac createHmacSha512Digest(byte[] key) {
  SHA512Digest digest = new SHA512Digest();
  HMac hMac = new HMac(digest);
  hMac.init(new KeyParameter(key));
  return hMac;
}

代码示例来源:origin: com.madgag.spongycastle/core

/**
 * Performs the extract part of the key derivation function.
 *
 * @param salt the salt to use
 * @param ikm  the input keying material
 * @return the PRK as KeyParameter
 */
private KeyParameter extract(byte[] salt, byte[] ikm)
{
  if (salt == null)
  {
    // TODO check if hashLen is indeed same as HMAC size
    hMacHash.init(new KeyParameter(new byte[hashLen]));
  }
  else
  {
    hMacHash.init(new KeyParameter(salt));
  }
  hMacHash.update(ikm, 0, ikm.length);
  byte[] prk = new byte[hashLen];
  hMacHash.doFinal(prk, 0);
  return new KeyParameter(prk);
}

代码示例来源:origin: com.madgag.spongycastle/core

public void init(DerivationParameters param)
{
  if (!(param instanceof HKDFParameters))
  {
    throw new IllegalArgumentException(
      "HKDF parameters required for HKDFBytesGenerator");
  }
  HKDFParameters params = (HKDFParameters)param;
  if (params.skipExtract())
  {
    // use IKM directly as PRK
    hMacHash.init(new KeyParameter(params.getIKM()));
  }
  else
  {
    hMacHash.init(extract(params.getSalt(), params.getIKM()));
  }
  info = params.getInfo();
  generatedBytes = 0;
  currentT = new byte[hashLen];
}

代码示例来源:origin: com.madgag.spongycastle/core

public BigInteger nextK()
{
  byte[] t = new byte[((n.bitLength() + 7) / 8)];
  for (;;)
  {
    int tOff = 0;
    while (tOff < t.length)
    {
      hMac.update(V, 0, V.length);
      hMac.doFinal(V, 0);
      int len = Math.min(t.length - tOff, V.length);
      System.arraycopy(V, 0, t, tOff, len);
      tOff += len;
    }
    BigInteger k = bitsToInt(t);
    if (k.compareTo(ZERO) > 0 && k.compareTo(n) < 0)
    {
      return k;
    }
    hMac.update(V, 0, V.length);
    hMac.update((byte)0x00);
    hMac.doFinal(K, 0);
    hMac.init(new KeyParameter(K));
    hMac.update(V, 0, V.length);
    hMac.doFinal(V, 0);
  }
}

代码示例来源:origin: com.madgag/sc-light-jdk15on

private static void hmac_hash(Digest digest, byte[] secret, byte[] seed, byte[] out)
{
  HMac mac = new HMac(digest);
  KeyParameter param = new KeyParameter(secret);
  byte[] a = seed;
  int size = digest.getDigestSize();
  int iterations = (out.length + size - 1) / size;
  byte[] buf = new byte[mac.getMacSize()];
  byte[] buf2 = new byte[mac.getMacSize()];
  for (int i = 0; i < iterations; i++)
  {
    mac.init(param);
    mac.update(a, 0, a.length);
    mac.doFinal(buf, 0);
    a = buf;
    mac.init(param);
    mac.update(a, 0, a.length);
    mac.update(seed, 0, seed.length);
    mac.doFinal(buf2, 0);
    System.arraycopy(buf2, 0, out, (size * i), Math.min(size, out.length - (size * i)));
  }
}

代码示例来源:origin: com.madgag/scprov-jdk15on

public void engineStore(OutputStream stream, char[] password) 
  throws IOException
{
  DataOutputStream    dOut = new DataOutputStream(stream);
  byte[]              salt = new byte[STORE_SALT_SIZE];
  int                 iterationCount = MIN_ITERATIONS + (random.nextInt() & 0x3ff);
  random.nextBytes(salt);
  dOut.writeInt(STORE_VERSION);
  dOut.writeInt(salt.length);
  dOut.write(salt);
  dOut.writeInt(iterationCount);
  HMac                    hMac = new HMac(new SHA1Digest());
  MacOutputStream         mOut = new MacOutputStream(hMac);
  PBEParametersGenerator  pbeGen = new PKCS12ParametersGenerator(new SHA1Digest());
  byte[]                  passKey = PBEParametersGenerator.PKCS12PasswordToBytes(password);
  pbeGen.init(passKey, salt, iterationCount);
  hMac.init(pbeGen.generateDerivedMacParameters(hMac.getMacSize() * 8));
  for (int i = 0; i != passKey.length; i++)
  {
    passKey[i] = 0;
  }
  saveStore(new TeeOutputStream(dOut, mOut));
  byte[]  mac = new byte[hMac.getMacSize()];
  hMac.doFinal(mac, 0);
  dOut.write(mac);
  dOut.close();
}

代码示例来源:origin: com.madgag.spongycastle/prov

hMac.init(pbeGen.generateDerivedMacParameters(hMac.getMacSize()));
hMac.init(pbeGen.generateDerivedMacParameters(hMac.getMacSize() * 8));

代码示例来源:origin: com.madgag.spongycastle/bctls-jdk15on

protected void hmacHash(Digest digest, byte[] secret, int secretOff, int secretLen, byte[] seed, byte[] output)
{
  HMac mac = new HMac(digest);
  mac.init(new KeyParameter(secret, secretOff, secretLen));
  byte[] a = seed;
  int macSize = mac.getMacSize();
  byte[] b1 = new byte[macSize];
  byte[] b2 = new byte[macSize];
  int pos = 0;
  while (pos < output.length)
  {
    mac.update(a, 0, a.length);
    mac.doFinal(b1, 0);
    a = b1;
    mac.update(a, 0, a.length);
    mac.update(seed, 0, seed.length);
    mac.doFinal(b2, 0);
    System.arraycopy(b2, 0, output, pos, Math.min(macSize, output.length - pos));
    pos += macSize;
  }
}

代码示例来源:origin: com.madgag.spongycastle/core

hMac.init(new KeyParameter(K));
hMac.init(new KeyParameter(K));
hMac.init(new KeyParameter(K));

代码示例来源:origin: com.madgag.spongycastle/core

static void hmac_hash(Digest digest, byte[] secret, byte[] seed, byte[] out)
{
  HMac mac = new HMac(digest);
  mac.init(new KeyParameter(secret));
  byte[] a = seed;
  int size = digest.getDigestSize();
  int iterations = (out.length + size - 1) / size;
  byte[] buf = new byte[mac.getMacSize()];
  byte[] buf2 = new byte[mac.getMacSize()];
  for (int i = 0; i < iterations; i++)
  {
    mac.update(a, 0, a.length);
    mac.doFinal(buf, 0);
    a = buf;
    mac.update(a, 0, a.length);
    mac.update(seed, 0, seed.length);
    mac.doFinal(buf2, 0);
    System.arraycopy(buf2, 0, out, (size * i), Math.min(size, out.length - (size * i)));
  }
}

代码示例来源:origin: com.madgag.spongycastle/core

/**
 * Create a {@link SimulatedTlsSRPIdentityManager} that implements the algorithm from RFC 5054 2.5.1.3
 *
 * @param group the {@link SRP6GroupParameters} defining the group that SRP is operating in
 * @param seedKey the secret "seed key" referred to in RFC 5054 2.5.1.3
 * @return an instance of {@link SimulatedTlsSRPIdentityManager}
 */
public static SimulatedTlsSRPIdentityManager getRFC5054Default(SRP6GroupParameters group, byte[] seedKey)
{
  SRP6VerifierGenerator verifierGenerator = new SRP6VerifierGenerator();
  verifierGenerator.init(group, TlsUtils.createHash(HashAlgorithm.sha1));
  HMac mac = new HMac(TlsUtils.createHash(HashAlgorithm.sha1));
  mac.init(new KeyParameter(seedKey));
  return new SimulatedTlsSRPIdentityManager(group, verifierGenerator, mac);
}

代码示例来源:origin: com.madgag.spongycastle/bcpkix-jdk15on

static MacCalculator createMacCalculator(final ASN1ObjectIdentifier digestAlgorithm, ExtendedDigest digest, final PKCS12PBEParams pbeParams, final char[] password)
{
  PKCS12ParametersGenerator pGen = new PKCS12ParametersGenerator(digest);
  pGen.init(PKCS12ParametersGenerator.PKCS12PasswordToBytes(password), pbeParams.getIV(), pbeParams.getIterations().intValue());
  final KeyParameter keyParam = (KeyParameter)pGen.generateDerivedMacParameters(digest.getDigestSize() * 8);
  final HMac hMac = new HMac(digest);
  hMac.init(keyParam);
  return new MacCalculator()
  {
    public AlgorithmIdentifier getAlgorithmIdentifier()
    {
      return new AlgorithmIdentifier(digestAlgorithm, pbeParams);
    }
    public OutputStream getOutputStream()
    {
      return new MacOutputStream(hMac);
    }
    public byte[] getMac()
    {
      byte[] res = new byte[hMac.getMacSize()];
      hMac.doFinal(res, 0);
      return res;
    }
    public GenericKey getKey()
    {
      return new GenericKey(getAlgorithmIdentifier(), PKCS12ParametersGenerator.PKCS12PasswordToBytes(password));
    }
  };
}

代码示例来源:origin: com.madgag.spongycastle/pkix

static MacCalculator createMacCalculator(final ASN1ObjectIdentifier digestAlgorithm, ExtendedDigest digest, final PKCS12PBEParams pbeParams, final char[] password)
{
  PKCS12ParametersGenerator pGen = new PKCS12ParametersGenerator(digest);
  pGen.init(PKCS12ParametersGenerator.PKCS12PasswordToBytes(password), pbeParams.getIV(), pbeParams.getIterations().intValue());
  final KeyParameter keyParam = (KeyParameter)pGen.generateDerivedMacParameters(digest.getDigestSize() * 8);
  final HMac hMac = new HMac(digest);
  hMac.init(keyParam);
  return new MacCalculator()
  {
    public AlgorithmIdentifier getAlgorithmIdentifier()
    {
      return new AlgorithmIdentifier(digestAlgorithm, pbeParams);
    }
    public OutputStream getOutputStream()
    {
      return new MacOutputStream(hMac);
    }
    public byte[] getMac()
    {
      byte[] res = new byte[hMac.getMacSize()];
      hMac.doFinal(res, 0);
      return res;
    }
    public GenericKey getKey()
    {
      return new GenericKey(getAlgorithmIdentifier(), PKCS12ParametersGenerator.PKCS12PasswordToBytes(password));
    }
  };
}

代码示例来源:origin: OPCFoundation/UA-Java-Legacy

private HMac createMac(SecurityAlgorithm algorithm, KeyParameter param)
    throws ServiceResultException {
  HMac hmac = null;
  if (algorithm.equals(SecurityAlgorithm.HmacSha1)) {
    hmac = new HMac(new SHA1Digest());
  } else if (algorithm.equals(SecurityAlgorithm.HmacSha256)) {
    hmac = new HMac(new SHA256Digest());
  } else {
    throw new ServiceResultException(
        StatusCodes.Bad_SecurityPolicyRejected,
        "Unsupported symmetric signature algorithm: " + algorithm);
  }
  hmac.init(param);
  return hmac;
}

代码示例来源:origin: com.madgag.spongycastle/core

mac.init(new KeyParameter(macKey));

相关文章