byte[] rndBytes = BigIntegers.asUnsignedByteArray(bi);
private static byte[] getPadded(BigInteger n, int length) { byte[] bs = BigIntegers.asUnsignedByteArray(n); if (bs.length < length) { byte[] tmp = new byte[length]; System.arraycopy(bs, 0, tmp, length - bs.length, bs.length); bs = tmp; } return bs; } }
private static byte[] getPadded(BigInteger n, int length) { byte[] bs = BigIntegers.asUnsignedByteArray(n); if (bs.length < length) { byte[] tmp = new byte[length]; System.arraycopy(bs, 0, tmp, length - bs.length, bs.length); bs = tmp; } return bs; } }
protected byte[] calculatePremasterSecret(BigInteger modulus, BigInteger privateKey, BigInteger publicKey) { if (modulus.compareTo(BigInteger.ZERO) == 0) { LOGGER.warn("Modulus is ZERO. Returning empty premaster Secret"); return new byte[0]; } return BigIntegers.asUnsignedByteArray(publicKey.modPow(privateKey.abs(), modulus.abs())); }
public static void writeDHParameter(BigInteger x, OutputStream output) throws IOException { TlsUtils.writeOpaque16(BigIntegers.asUnsignedByteArray(x), output); } }
public byte[] generateClientKeyExchange() throws IOException { return BigIntegers.asUnsignedByteArray(srpClient.generateClientCredentials(s, this.SRP_identity, this.SRP_password)); }
private static void updateDigest(Digest digest, BigInteger bigInteger) { byte[] byteArray = BigIntegers.asUnsignedByteArray(bigInteger); digest.update(byteArray, 0, byteArray.length); Arrays.fill(byteArray, (byte)0); }
private void addFieldElement(Digest digest, ECFieldElement v) { byte[] p = BigIntegers.asUnsignedByteArray(curveLength, v.toBigInteger()); digest.update(p, 0, p.length); } }
private static void updateMac(Mac mac, BigInteger bigInteger) { byte[] byteArray = BigIntegers.asUnsignedByteArray(bigInteger); mac.update(byteArray, 0, byteArray.length); Arrays.fill(byteArray, (byte)0); }
protected KeyParameter generateKey(BigInteger n, BigInteger r, int keyLen) { byte[] R = BigIntegers.asUnsignedByteArray((n.bitLength() + 7) / 8, r); // Initialise the KDF kdf.init(new KDFParameters(R, null)); // Generate the secret key byte[] K = new byte[keyLen]; kdf.generateBytes(K, 0, K.length); return new KeyParameter(K); } }
public static byte[] calculateDHBasicAgreement(DHPublicKeyParameters publicKey, DHPrivateKeyParameters privateKey) { DHBasicAgreement basicAgreement = new DHBasicAgreement(); basicAgreement.init(privateKey); BigInteger agreementValue = basicAgreement.calculateAgreement(publicKey); /* * RFC 5246 8.1.2. Leading bytes of Z that contain all zero bits are stripped before it is * used as the pre_master_secret. */ return BigIntegers.asUnsignedByteArray(agreementValue); }
protected KeyParameter generateKey(BigInteger n, BigInteger r, int keyLen) { byte[] R = BigIntegers.asUnsignedByteArray((n.bitLength() + 7) / 8, r); // Initialise the KDF kdf.init(new KDFParameters(R, null)); // Generate the secret key byte[] K = new byte[keyLen]; kdf.generateBytes(K, 0, K.length); return new KeyParameter(K); } }
public static byte[] calculateDHBasicAgreement(DHPublicKeyParameters publicKey, DHPrivateKeyParameters privateKey) { DHBasicAgreement basicAgreement = new DHBasicAgreement(); basicAgreement.init(privateKey); BigInteger agreementValue = basicAgreement.calculateAgreement(publicKey); /* * RFC 5246 8.1.2. Leading bytes of Z that contain all zero bits are stripped before it is * used as the pre_master_secret. */ return BigIntegers.asUnsignedByteArray(agreementValue); }
public static byte[] calculateECDHBasicAgreement(ECPublicKeyParameters publicKey, ECPrivateKeyParameters privateKey) { ECDHBasicAgreement basicAgreement = new ECDHBasicAgreement(); basicAgreement.init(privateKey); BigInteger agreementValue = basicAgreement.calculateAgreement(publicKey); /* * RFC 4492 5.10. Note that this octet string (Z in IEEE 1363 terminology) as output by * FE2OSP, the Field Element to Octet String Conversion Primitive, has constant length for * any given field; leading zeros found in this octet string MUST NOT be truncated. */ return BigIntegers.asUnsignedByteArray(basicAgreement.getFieldSize(), agreementValue); }
private static void updateDigestIncludingSize(Digest digest, BigInteger bigInteger) { byte[] byteArray = BigIntegers.asUnsignedByteArray(bigInteger); digest.update(intToByteArray(byteArray.length), 0, 4); digest.update(byteArray, 0, byteArray.length); Arrays.fill(byteArray, (byte)0); }
private static void updateDigestIncludingSize(Digest digest, BigInteger bigInteger) { byte[] byteArray = BigIntegers.asUnsignedByteArray(bigInteger); digest.update(intToByteArray(byteArray.length), 0, 4); digest.update(byteArray, 0, byteArray.length); Arrays.fill(byteArray, (byte)0); }
public byte[] generatePremasterSecret() throws IOException { /* * Diffie-Hellman basic key agreement */ DHBasicAgreement dhAgree = new DHBasicAgreement(); dhAgree.init(dhAgreeClientKeyPair.getPrivate()); BigInteger agreement = dhAgree.calculateAgreement(dhAgreeServerPublicKey); return BigIntegers.asUnsignedByteArray(agreement); }
public byte[] generatePremasterSecret() throws IOException { /* * Diffie-Hellman basic key agreement */ DHBasicAgreement dhAgree = new DHBasicAgreement(); dhAgree.init(dhAgreeClientKeyPair.getPrivate()); BigInteger agreement = dhAgree.calculateAgreement(dhAgreeServerPublicKey); return BigIntegers.asUnsignedByteArray(agreement); }
public static byte[] calculateECDHBasicAgreement(ECPublicKeyParameters publicKey, ECPrivateKeyParameters privateKey) { ECDHBasicAgreement basicAgreement = new ECDHBasicAgreement(); basicAgreement.init(privateKey); BigInteger agreementValue = basicAgreement.calculateAgreement(publicKey); /* * RFC 4492 5.10. Note that this octet string (Z in IEEE 1363 terminology) as output by * FE2OSP, the Field Element to Octet String Conversion Primitive, has constant length for * any given field; leading zeros found in this octet string MUST NOT be truncated. */ return BigIntegers.asUnsignedByteArray(basicAgreement.getFieldSize(), agreementValue); }
@Override public void serialize(BinaryWriter writer) throws IOException { writer.write(ArrayUtils.reverseArray(Numeric.hexStringToByteArray(assetId))); byte[] value = BigIntegers.asUnsignedByteArray(8, NEOAsset.toBigInt(this.value)); writer.write(ArrayUtils.reverseArray(value)); writer.write(KeyUtils.toScriptHash(this.address)); } }