org.bouncycastle.util.Arrays类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(604)

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

Arrays介绍

[英]General array utilities.
[中]通用阵列实用程序。

代码示例

代码示例来源:origin: spring-projects/spring-security

private void generatesDifferentCipherTexts(BytesEncryptor bcEncryptor) {
  byte[] encrypted1 = bcEncryptor.encrypt(testData);
  byte[] encrypted2 = bcEncryptor.encrypt(testData);
  Assert.assertFalse(Arrays.areEqual(encrypted1, encrypted2));
  byte[] decrypted1 = bcEncryptor.decrypt(encrypted1);
  byte[] decrypted2 = bcEncryptor.decrypt(encrypted2);
  Assert.assertArrayEquals(testData, decrypted1);
  Assert.assertArrayEquals(testData, decrypted2);
}

代码示例来源:origin: cloudfoundry/uaa

public byte[] encrypt(String plaintext) throws EncryptionServiceException {
  try {
    byte[] newSalt = generateRandomArray(PBKDF2_SALT_SIZE_BYTES);
    SecretKey key = new SecretKeySpec(generateKey(newSalt), CIPHER);
    Cipher myCipher = Cipher.getInstance(CIPHERSCHEME);
    byte[] newNonce = generateRandomArray(GCM_IV_NONCE_SIZE_BYTES);
    GCMParameterSpec spec = new GCMParameterSpec(GCM_AUTHENTICATION_TAG_SIZE_BITS, newNonce);
    myCipher.init(Cipher.ENCRYPT_MODE, key, spec);
    byte[] bytes = plaintext.getBytes();
    return Arrays.concatenate(newNonce, newSalt, myCipher.doFinal(bytes));
  } catch (Exception e) {
    logger.error("Encryption failed", e);
    throw new EncryptionServiceException(e);
  }
}

代码示例来源:origin: cloudfoundry/uaa

public byte[] decrypt(byte[] encrypt) throws EncryptionServiceException {
  try {
    byte[] myNonce = new byte[GCM_IV_NONCE_SIZE_BYTES];
    byte[] mySalt = new byte[PBKDF2_SALT_SIZE_BYTES];
    ByteArrayInputStream fileInputStream = new ByteArrayInputStream(encrypt);
    fileInputStream.read(myNonce);
    fileInputStream.read(mySalt);
    SecretKey key = new SecretKeySpec(generateKey(mySalt), CIPHER);
    Cipher myCipher = Cipher.getInstance(CIPHERSCHEME);
    GCMParameterSpec spec = new GCMParameterSpec(GCM_AUTHENTICATION_TAG_SIZE_BITS, myNonce);
    myCipher.init(Cipher.DECRYPT_MODE, key, spec);
    return myCipher.doFinal(Arrays.copyOfRange(encrypt, GCM_IV_NONCE_SIZE_BYTES + PBKDF2_SALT_SIZE_BYTES, encrypt.length));
  } catch (Exception e) {
    logger.error("Decryption failed", e);
    throw new EncryptionServiceException(e);
  }
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

protected BigInteger decodeValue(BigInteger n, byte[] buf, int off, int len)
{
  byte[] bs = Arrays.copyOfRange(buf, off, off + len);
  return checkValue(n, new BigInteger(1, bs));
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

private XMSSMTPublicKey(ASN1Sequence seq)
{
  if (!ASN1Integer.getInstance(seq.getObjectAt(0)).getValue().equals(BigInteger.valueOf(0)))
  {
    throw new IllegalArgumentException("unknown version of sequence");
  }
  this.publicSeed = Arrays.clone(DEROctetString.getInstance(seq.getObjectAt(1)).getOctets());
  this.root = Arrays.clone(DEROctetString.getInstance(seq.getObjectAt(2)).getOctets());
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

public MacData(
  DigestInfo  digInfo,
  byte[]      salt,
  int         iterationCount)
{
  this.digInfo = digInfo;
  this.salt = Arrays.clone(salt);
  this.iterationCount = BigInteger.valueOf(iterationCount);
}

代码示例来源:origin: Yubico/java-webauthn-server

public static ByteArray ecPublicKeyToRaw(ECPublicKey key) {
  byte[] x = key.getW().getAffineX().toByteArray();
  byte[] y = key.getW().getAffineY().toByteArray();
  byte[] xPadding = new byte[Math.max(0, 32 - x.length)];
  byte[] yPadding = new byte[Math.max(0, 32 - y.length)];
  Arrays.fill(xPadding, (byte) 0);
  Arrays.fill(yPadding, (byte) 0);
  return new ByteArray(org.bouncycastle.util.Arrays.concatenate(
    new byte[]{ 0x04 },
    org.bouncycastle.util.Arrays.concatenate(
      xPadding,
      Arrays.copyOfRange(x, Math.max(0, x.length - 32), x.length)
    ),
    org.bouncycastle.util.Arrays.concatenate(
      yPadding,
      Arrays.copyOfRange(y, Math.max(0, y.length - 32), y.length)
    )
  ));
}

代码示例来源:origin: redfish64/TinyTravelTracker

/**
 * Adds another polynomial which can have a different number of coefficients.
 *
 * @param b another polynomial
 */
public void add(BigIntPolynomial b)
{
  if (b.coeffs.length > coeffs.length)
  {
    int N = coeffs.length;
    coeffs = Arrays.copyOf(coeffs, b.coeffs.length);
    for (int i = N; i < coeffs.length; i++)
    {
      coeffs[i] = Constants.BIGINT_ZERO;
    }
  }
  for (int i = 0; i < b.coeffs.length; i++)
  {
    coeffs[i] = coeffs[i].add(b.coeffs[i]);
  }
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

private void encodeValue(BigInteger n, BigInteger x, byte[] buf, int off, int len)
  {
    byte[] bs = checkValue(n, x).toByteArray();
    int bsOff = Math.max(0, bs.length - len);
    int bsLen = bs.length - bsOff;

    int pos = len - bsLen;
    Arrays.fill(buf, off, off + pos, (byte)0);
    System.arraycopy(bs, bsOff, buf, off + pos, bsLen);
  }
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

protected void engineInit(
  byte[] params,
  String format)
  throws IOException
{
  if (this.isASN1FormatString(format))
  {
    RC2CBCParameter p = RC2CBCParameter.getInstance(ASN1Primitive.fromByteArray(params));
    if (p.getRC2ParameterVersion() != null)
    {
      parameterVersion = p.getRC2ParameterVersion().intValue();
    }
    iv = p.getIV();
    return;
  }
  if (format.equals("RAW"))
  {
    engineInit(params);
    return;
  }
  throw new IOException("Unknown parameters format in IV parameters object");
}

代码示例来源:origin: redfish64/TinyTravelTracker

/**
 * Subtracts another polynomial which can have a different number of coefficients.
 *
 * @param b another polynomial
 */
public void sub(BigIntPolynomial b)
{
  if (b.coeffs.length > coeffs.length)
  {
    int N = coeffs.length;
    coeffs = Arrays.copyOf(coeffs, b.coeffs.length);
    for (int i = N; i < coeffs.length; i++)
    {
      coeffs[i] = Constants.BIGINT_ZERO;
    }
  }
  for (int i = 0; i < b.coeffs.length; i++)
  {
    coeffs[i] = coeffs[i].subtract(b.coeffs[i]);
  }
}

代码示例来源:origin: syncany/syncany

byte[] alteredCiphertext = Arrays.clone(originalCiphertext);		
alteredCiphertext[8] = (byte) (alteredCiphertext[8] ^ 0x08); // <<< Change 100$ to 900$

代码示例来源:origin: resteasy/Resteasy

if (! org.bouncycastle.util.Arrays.constantTimeAreEqual(expectedAuthTag, authTag)) {

代码示例来源:origin: martinpaljak/GlobalPlatformPro

public HashRefDo(final byte[] data) {
  if (data == null)
    hash = new byte[0];
  else
    hash = Arrays.copyOf(data, data.length);
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

protected void checkMAC(long seqNo, short type, byte[] recBuf, int recStart, int recEnd, byte[] calcBuf, int calcOff, int calcLen)
  throws IOException
{
  byte[] receivedMac = Arrays.copyOfRange(recBuf, recStart, recEnd);
  byte[] computedMac = readMac.calculateMac(seqNo, type, calcBuf, calcOff, calcLen);
  if (!Arrays.constantTimeAreEqual(receivedMac, computedMac))
  {
    throw new TlsFatalAlert(AlertDescription.bad_record_mac);
  }
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

protected byte[] engineGenerateSecret()
  throws IllegalStateException
{
  byte[] rv = Arrays.clone(shared);
  Arrays.fill(shared, (byte)0);
  return rv;
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

private static byte[] genPad(byte b, int count)
  {
    byte[] padding = new byte[count];
    Arrays.fill(padding, b);
    return padding;
  }
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

private static void checkNamedCurve(int[] namedCurves, int namedCurve) throws IOException
{
  if (namedCurves != null && !Arrays.contains(namedCurves, namedCurve))
  {
    /*
     * RFC 4492 4. [...] servers MUST NOT negotiate the use of an ECC cipher suite
     * unless they can complete the handshake while respecting the choice of curves
     * and compression techniques specified by the client.
     */
    throw new TlsFatalAlert(AlertDescription.illegal_parameter);
  }
}

代码示例来源:origin: redfish64/TinyTravelTracker

public static byte[] createSupportedPointFormatsExtension(short[] ecPointFormats) throws IOException
{
  if (ecPointFormats == null || !Arrays.contains(ecPointFormats, ECPointFormat.uncompressed))
  {
    /*
     * RFC 4492 5.1. If the Supported Point Formats Extension is indeed sent, it MUST
     * contain the value 0 (uncompressed) as one of the items in the list of point formats.
     */
    // NOTE: We add it at the end (lowest preference)
    ecPointFormats = Arrays.append(ecPointFormats, ECPointFormat.uncompressed);
  }
  return TlsUtils.encodeUint8ArrayWithUint8Length(ecPointFormats);
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

public static ECField convertField(FiniteField field)
{
  if (ECAlgorithms.isFpField(field))
  {
    return new ECFieldFp(field.getCharacteristic());
  }
  else //if (ECAlgorithms.isF2mField(curveField))
  {
    Polynomial poly = ((PolynomialExtensionField)field).getMinimalPolynomial();
    int[] exponents = poly.getExponentsPresent();
    int[] ks = Arrays.reverse(Arrays.copyOfRange(exponents, 1, exponents.length - 1));
    return new ECFieldF2m(poly.getDegree(), ks);
  }
}

相关文章