@Override protected String encodeToken(String token) throws Base64Exception { return Base64UrlUtility.encode(token); } }
public static byte[] decodeSequence(String encodedSequence) throws SecurityException { try { return Base64UrlUtility.decode(encodedSequence); } catch (Exception ex) { throw new SecurityException(ex); } }
public static String encode(byte[] id) { return encodeChunk(id, 0, id.length); }
@Override public void writeTo(JwsDetachedSignature parts, Class<?> cls, Type t, Annotation[] anns, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException { JoseUtils.traceHeaders(parts.getHeaders()); byte[] finalBytes = parts.getSignature().sign(); if (!parts.isUseJwsJsonSignatureFormat()) { os.write(StringUtils.toBytesASCII(parts.getEncodedHeaders())); byte[] dotBytes = new byte[]{'.'}; os.write(dotBytes); os.write(dotBytes); Base64UrlUtility.encodeAndStream(finalBytes, 0, finalBytes.length, os); } else { // use flattened JWS JSON format os.write(StringUtils.toBytesASCII("{")); String headersProp = "\"protected\":\"" + parts.getEncodedHeaders() + "\""; os.write(StringUtils.toBytesUTF8(headersProp)); os.write(StringUtils.toBytesASCII(",")); String sigProp = "\"signature\":\"" + Base64UrlUtility.encode(finalBytes) + "\""; os.write(StringUtils.toBytesUTF8(sigProp)); os.write(StringUtils.toBytesASCII("}")); } }
public static void startJweContent(OutputStream os, JweHeaders headers, byte[] encryptedContentEncryptionKey, byte[] cipherInitVector) throws IOException { byte[] jsonBytes = StringUtils.toBytesUTF8(getHeadersJson(headers)); Base64UrlUtility.encodeAndStream(jsonBytes, 0, jsonBytes.length, os); byte[] dotBytes = new byte[]{'.'}; os.write(dotBytes); Base64UrlUtility.encodeAndStream(encryptedContentEncryptionKey, 0, encryptedContentEncryptionKey.length, os); os.write(dotBytes); Base64UrlUtility.encodeAndStream(cipherInitVector, 0, cipherInitVector.length, os); os.write(dotBytes); os.flush(); }
public static void startJweContent(OutputStream os, JweHeaders headers, byte[] encryptedContentEncryptionKey, byte[] cipherInitVector) throws IOException { byte[] jsonBytes = StringUtils.toBytesUTF8(getHeadersJson(headers)); Base64UrlUtility.encodeAndStream(jsonBytes, 0, jsonBytes.length, os); byte[] dotBytes = new byte[]{'.'}; os.write(dotBytes); Base64UrlUtility.encodeAndStream(encryptedContentEncryptionKey, 0, encryptedContentEncryptionKey.length, os); os.write(dotBytes); Base64UrlUtility.encodeAndStream(cipherInitVector, 0, cipherInitVector.length, os); os.write(dotBytes); os.flush(); }
@Override protected String encodeToken(String token) throws Base64Exception { return Base64UrlUtility.encode(token); } }
public static byte[] decodeSequence(String encodedSequence) throws SecurityException { try { return Base64UrlUtility.decode(encodedSequence); } catch (Exception ex) { throw new SecurityException(ex); } }
public static String encode(byte[] id) { return encodeChunk(id, 0, id.length); }
@Override public void flush() throws IOException { if (flushed) { return; } if (writeSignature) { byte[] finalBytes = signature.sign(); out.write(new byte[]{'.'}); Base64UrlUtility.encodeAndStream(finalBytes, 0, finalBytes.length, out); } else { super.flush(); } flushed = true; }
public static String encodeBytes(byte[] bytes) throws SecurityException { try { return Base64UrlUtility.encode(bytes); } catch (Exception ex) { throw new SecurityException(ex); } }
public HmacJwsSignatureProvider(String encodedKey, SignatureAlgorithm algo) { super(algo); try { this.key = Base64UrlUtility.decode(encodedKey); } catch (Base64Exception ex) { LOG.warning("Hmac key can not be decoded"); throw new JwsException(JwsException.Error.INVALID_KEY, ex); } }
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 void flush() throws IOException { if (flushed) { return; } if (writeSignature) { byte[] finalBytes = signature.sign(); out.write(new byte[]{'.'}); Base64UrlUtility.encodeAndStream(finalBytes, 0, finalBytes.length, out); } else { super.flush(); } flushed = true; }
public static String encodeBytes(byte[] bytes) throws SecurityException { try { return Base64UrlUtility.encode(bytes); } catch (Exception ex) { throw new SecurityException(ex); } }
private InputStream decodeAssertion(String assertion) { try { byte[] deflatedToken = Base64UrlUtility.decode(assertion); return new ByteArrayInputStream(deflatedToken); } catch (Base64Exception ex) { throw new OAuthServiceException(OAuthConstants.INVALID_GRANT); } }
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,
private void encodeAndWrite(byte[] encryptedChunk, int off, int len, boolean finalWrite) throws IOException { byte[] theChunk = lastEncryptedDataChunk; int lenToEncode = len; if (theChunk != null) { theChunk = newArray(theChunk, 0, theChunk.length, encryptedChunk, off, len); lenToEncode = theChunk.length; off = 0; } else { theChunk = encryptedChunk; } int rem = finalWrite ? 0 : lenToEncode % 3; Base64UrlUtility.encodeAndStream(theChunk, off, lenToEncode - rem, out); out.flush(); if (rem > 0) { lastEncryptedDataChunk = newArray(theChunk, lenToEncode - rem, rem); } else { lastEncryptedDataChunk = null; } }
public static String encode(String str) { return encode(str.getBytes(StandardCharsets.UTF_8)); }
private byte[] getDecodedBytes(Object p2sHeader) { try { return Base64UrlUtility.decode(p2sHeader.toString()); } catch (Exception ex) { throw new JoseException(ex); } } @Override