/** * Create a DER decoder that will decode values from the given byte array. * * @param buf the byte array to decode */ public DERDecoder(byte[] buf) { this.bi = ByteIterator.ofBytes(buf); }
/** * Get a byte iterator for a byte array with interleave. * * @param bytes the array * @param interleave the interleave table to use * @return the byte iterator */ public static ByteIterator ofBytes(final byte[] bytes, final int[] interleave) { return ofBytes(bytes, 0, bytes.length, interleave); }
/** * Create a DER decoder that will decode values from the given byte array. * * @param buf the byte array to decode * @param offset the offset in the byte array of the first byte to read * @param length the maximum number of bytes to read from the byte array */ public DERDecoder(byte[] buf, int offset, int length) { this.bi = ByteIterator.ofBytes(buf, offset, length); }
public ByteIterator iterate() { return ByteIterator.ofBytes(content, 0, length); } }
private static byte[] modulusToByteArray(BigInteger modulus) { // As specified in https://tools.ietf.org/html/rfc7518#section-6.3.1, the extra zero-valued octet // needs to be omitted if present byte[] modulusByteArray = modulus.toByteArray(); if ((modulus.bitLength() % 8 == 0) && (modulusByteArray[0] == 0) && modulusByteArray.length > 1) { return ByteIterator.ofBytes(modulusByteArray, 1, modulusByteArray.length - 1).drain(); } else { return modulusByteArray; } }
/** * Get a byte iterator for a byte array. * * @param bytes the array * @return the byte iterator */ public static ByteIterator ofBytes(final byte... bytes) { Assert.checkNotNullParam("bytes", bytes); return ofBytes(bytes, 0, bytes.length); }
public ByteIterator doFinal(MessageDigest digest) { update(digest); return ByteIterator.ofBytes(digest.digest()); }
public ByteIterator sign(Signature signature) throws SignatureException { update(signature); return ByteIterator.ofBytes(signature.sign()); }
public ByteIterator doFinal(final MessageDigest digest) throws IllegalStateException { update(digest); return ByteIterator.ofBytes(digest.digest()); }
static byte[] generateNonce() { SecureRandom random = new SecureRandom(); byte[] nonceData = new byte[NONCE_SIZE]; random.nextBytes(nonceData); return ByteIterator.ofBytes(nonceData).base64Encode().drainToString().getBytes(StandardCharsets.US_ASCII); }
@Override public String createLogoutParameter(String sessionId) { try { Signature signature = Signature.getInstance(DEFAULT_SIGNATURE_ALGORITHM); signature.initSign(this.keyPair.getPrivate()); Base64.Encoder urlEncoder = Base64.getUrlEncoder(); return sessionId + "." + ByteIterator.ofBytes(urlEncoder.encode(ByteIterator.ofBytes(sessionId.getBytes(StandardCharsets.UTF_8)).sign(signature).drain())).asUtf8String().drainToString(); } catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException e) { throw new IllegalStateException(e); } }
private byte[] createErrorMessage() { JsonObjectBuilder objectBuilder = Json.createObjectBuilder(); objectBuilder.add("status", "invalid_token"); Object asDiscoveryUrl = serverConfig.get(CONFIG_OPENID_CONFIGURATION_URL); if (asDiscoveryUrl != null) { objectBuilder.add(CONFIG_OPENID_CONFIGURATION_URL, asDiscoveryUrl.toString()); } return ByteIterator.ofBytes(objectBuilder.build().toString().getBytes()).base64Encode().asUtf8().drain(); } }
/** * Convert the given OTP hash into hexadecimal format. * * @param otp the OTP hash * @return the hexadecimal value that corresponds to the given OTP hash */ public static String convertToHex(byte[] otp) { return ByteIterator.ofBytes(otp).hexEncode().drainToString(); }
private static char[] unmask(final String algorithm, final char[] initialKeyMaterial, final int iterationCount, final byte[] salt, final byte[] bytes) throws InvalidKeySpecException { final Cipher cipher = getCipher(algorithm, initialKeyMaterial, iterationCount, salt, Cipher.DECRYPT_MODE); try { return ByteIterator.ofBytes(cipher.doFinal(bytes)).asUtf8String().drainToString().toCharArray(); } catch (IllegalBlockSizeException | BadPaddingException e) { throw new InvalidKeySpecException(e); } }
public String generateHashedHexURP(final String userName, final String realm, final char[] password, final boolean utf8StringConversion) { byte[] hashedURP = generateHashedURP(userName, realm, password, utf8StringConversion); return ByteIterator.ofBytes(hashedURP).hexEncode().drainToString(); }
private String encodeUsingAlphabet(byte[] payload) { if (picketBoxCompatibility) { return picketBoxBased64Encode(payload); } else { CodePointIterator codePointIterator = isBase64(alphabet) ? ByteIterator.ofBytes(payload).base64Encode(getAlphabet64(alphabet), usePadding) : ByteIterator.ofBytes(payload).base32Encode(getAlphabet32(alphabet)); return codePointIterator.drainToString(); } }
private static void composeCryptBasedPassword(ByteArrayOutputStream out, UnixDESCryptPassword password) throws IOException { out.write(ModularCrypt.MOD_CRYPT.encode(password.getSalt() & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getSalt() >> 6 & 0x3f)); out.write(ByteIterator.ofBytes(password.getHash()).base64Encode(ModularCrypt.MOD_CRYPT, false).asUtf8().drain()); }
/** * Generate PEM content containing a PKCS #10 certificate signing request. * * @param target the target byte string builder (must not be {@code null}) * @param certificateSigningRequest the PKCS #10 certificate signing request (must not be {@code null}) * @since 1.2.0 */ public static void generatePemPKCS10CertificateSigningRequest(ByteStringBuilder target, PKCS10CertificateSigningRequest certificateSigningRequest) { Assert.checkNotNullParam("target", target); Assert.checkNotNullParam("certificateSigningRequest", certificateSigningRequest); generatePemContent(target, CERTIFICATE_REQUEST_FORMAT, ByteIterator.ofBytes(certificateSigningRequest.getEncoded())); } }
private static void composeBsdCryptBasedPassword(ByteArrayOutputStream out, BSDUnixDESCryptPassword password) throws IOException { out.write(ModularCrypt.MOD_CRYPT.encode(password.getIterationCount() & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getIterationCount() >> 6 & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getIterationCount() >> 12 & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getIterationCount() >> 18 & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getSalt() & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getSalt() >> 6 & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getSalt() >> 12 & 0x3f)); out.write(ModularCrypt.MOD_CRYPT.encode(password.getSalt() >> 18 & 0x3f)); out.write(ByteIterator.ofBytes(password.getHash()).base64Encode(ModularCrypt.MOD_CRYPT, false).asUtf8().drain()); }
private static byte[] composeDigestSalt(SaltedSimpleDigestPassword password) { return ByteIterator.ofBytes(new ByteStringBuilder() .append(password.getDigest()) .append(password.getSalt()) .toArray() ).base64Encode().asUtf8().drain(); }