public static String encode(byte[] id) { return encodeChunk(id, 0, id.length); }
public static String encode(byte[] id) { return encodeChunk(id, 0, id.length); }
public JweCompactBuilder(JweHeaders headers, byte[] encryptedContentEncryptionKey, byte[] cipherInitVector, byte[] encryptedContentWithTag, int authTagLengthBits) { jweContentBuilder = startJweContent(new StringBuilder(), headers, encryptedContentEncryptionKey, cipherInitVector); this.encodedEncryptedContent = Base64UrlUtility.encodeChunk( encryptedContentWithTag, 0, encryptedContentWithTag.length - authTagLengthBits / 8); this.encodedAuthTag = Base64UrlUtility.encodeChunk( encryptedContentWithTag, encryptedContentWithTag.length - authTagLengthBits / 8, authTagLengthBits / 8); } public static String startJweContent(JweHeaders headers,
public JweCompactBuilder(JweHeaders headers, byte[] encryptedContentEncryptionKey, byte[] cipherInitVector, byte[] encryptedContentWithTag, int authTagLengthBits) { jweContentBuilder = startJweContent(new StringBuilder(), headers, encryptedContentEncryptionKey, cipherInitVector); this.encodedEncryptedContent = Base64UrlUtility.encodeChunk( encryptedContentWithTag, 0, encryptedContentWithTag.length - authTagLengthBits / 8); this.encodedAuthTag = Base64UrlUtility.encodeChunk( encryptedContentWithTag, encryptedContentWithTag.length - authTagLengthBits / 8, authTagLengthBits / 8); } public static String startJweContent(JweHeaders headers,
@Override public byte[] getEncryptedContentEncryptionKey(JweHeaders headers, byte[] cek) { byte[] wrappedKeyAndTag = super.getEncryptedContentEncryptionKey(headers, cek); byte[] wrappedKey = new byte[wrappedKeyAndTag.length - 128 / 8]; System.arraycopy(wrappedKeyAndTag, 0, wrappedKey, 0, wrappedKeyAndTag.length - 128 / 8); String encodedTag = Base64UrlUtility.encodeChunk(wrappedKeyAndTag, wrappedKeyAndTag.length - 128 / 8, 128 / 8); headers.setHeader("tag", encodedTag); // Cleanup Arrays.fill(wrappedKeyAndTag, (byte) 0); return wrappedKey; } protected AlgorithmParameterSpec getAlgorithmParameterSpec(JweHeaders headers) {
@Override public byte[] getEncryptedContentEncryptionKey(JweHeaders headers, byte[] cek) { byte[] wrappedKeyAndTag = super.getEncryptedContentEncryptionKey(headers, cek); byte[] wrappedKey = new byte[wrappedKeyAndTag.length - 128 / 8]; System.arraycopy(wrappedKeyAndTag, 0, wrappedKey, 0, wrappedKeyAndTag.length - 128 / 8); String encodedTag = Base64UrlUtility.encodeChunk(wrappedKeyAndTag, wrappedKeyAndTag.length - 128 / 8, 128 / 8); headers.setHeader("tag", encodedTag); // Cleanup Arrays.fill(wrappedKeyAndTag, (byte) 0); return wrappedKey; } protected AlgorithmParameterSpec getAlgorithmParameterSpec(JweHeaders headers) {
private static String calculateHash(String value, SignatureAlgorithm sigAlgo) { if (sigAlgo == SignatureAlgorithm.NONE) { throw new JwsException(JwsException.Error.INVALID_ALGORITHM); } String algoShaSizeString = sigAlgo.getJwaName().substring(2); String javaShaAlgo = "SHA-" + algoShaSizeString; int algoShaSize = Integer.parseInt(algoShaSizeString); int valueHashSize = (algoShaSize / 8) / 2; try { byte[] atBytes = StringUtils.toBytesASCII(value); byte[] digest = MessageDigestUtils.createDigest(atBytes, javaShaAlgo); return Base64UrlUtility.encodeChunk(digest, 0, valueHashSize); } catch (NoSuchAlgorithmException ex) { throw new OAuthServiceException(ex); } } public static void setStateClaimsProperty(OAuthRedirectionState state,
private static String calculateHash(String value, SignatureAlgorithm sigAlgo) { if (sigAlgo == SignatureAlgorithm.NONE) { throw new JwsException(JwsException.Error.INVALID_ALGORITHM); } String algoShaSizeString = sigAlgo.getJwaName().substring(2); String javaShaAlgo = "SHA-" + algoShaSizeString; int algoShaSize = Integer.parseInt(algoShaSizeString); int valueHashSize = (algoShaSize / 8) / 2; try { byte[] atBytes = StringUtils.toBytesASCII(value); byte[] digest = MessageDigestUtils.createDigest(atBytes, javaShaAlgo); return Base64UrlUtility.encodeChunk(digest, 0, valueHashSize); } catch (NoSuchAlgorithmException ex) { throw new OAuthServiceException(ex); } } public static void setStateClaimsProperty(OAuthRedirectionState state,