List of usage examples for org.apache.commons.codec.binary Base64 isArrayByteBase64
@Deprecated public static boolean isArrayByteBase64(final byte[] arrayOctet)
From source file:com.abiquo.abiserver.business.authentication.TokenUtils.java
/** * Returns an array containing each token field * <ul>/*from www. ja va 2 s .c o m*/ * <li>[0] => The token signature.</li> * <li>[1] => The token user name.</li> * <li>[2] => The token expiration time.</li> * </ul> * * @param token The token. * @return The token fields. * @throws Exception */ public static String[] getTokenFields(final String token) throws Exception { String base64Token = token; for (int j = 0; j < base64Token.length() % 4; j++) { base64Token = base64Token + "="; } if (!Base64.isArrayByteBase64(base64Token.getBytes())) { throw new Exception("Token is not Base64 encoded"); } String decodedToken = new String(Base64.decodeBase64(base64Token.getBytes())); return decodedToken.split(":"); }
From source file:com.amazonaws.eclipse.core.ui.preferences.ObfuscatingStringFieldEditor.java
public static boolean isBase64(String s) { return Base64.isArrayByteBase64(s.getBytes()); }
From source file:com.mastfrog.acteur.util.BasicCredentials.java
public static BasicCredentials parse(String header) { Matcher m = HEADER.matcher(header); if (m.matches()) { String base64 = m.group(1); // byte[] decoded = Base64.getDecoder().decode(base64); // String s = new String(decoded, UTF_8); byte[] bytes = base64.getBytes(UTF_8); if (Base64.isArrayByteBase64(bytes)) { bytes = Base64.decodeBase64(bytes); }//from w w w. j a v a 2 s . co m String s = new String(bytes, US_ASCII); m = UNPW.matcher(s); if (m.matches()) { String username = m.group(1); String password = m.group(2); return new BasicCredentials(username, password); } } return null; }
From source file:com.fiision.lib.core.codec.FwiBase64.java
static public boolean isBase64(byte[] base64Data) { return !(base64Data == null || base64Data.length == 0 || (base64Data.length % 4) != 0) && Base64.isArrayByteBase64(base64Data); }
From source file:com.google.nigori.common.TypeAdapterByteString.java
@SuppressWarnings("deprecation") // see comment below @Override//from w w w. j ava 2s . c o m public ByteString deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { byte[] jsonBytes = json.getAsString().getBytes(); // (drt24) Since android ships with an ancient version of org.apache.commons.codec which // overrides any version we ship we have to use old deprecated methods. if (Base64.isArrayByteBase64(jsonBytes)) { return ByteString.copyFrom(Base64.decodeBase64(jsonBytes)); } else { throw new JsonParseException("JSON element is not correctly base64 encoded."); } }
From source file:com.db4o.sync4o.SyncData.java
public SyncData(SyncKey key, byte[] data, Timestamp ts, char state) { if ((key == null) || (data == null) || !Base64.isArrayByteBase64(data) || (ts == null)) { throw new IllegalArgumentException(); }//from ww w. j a va 2 s . c om _key = key; _timestamp = (Timestamp) ts.clone(); _state = state; _data = data; }
From source file:com.ebay.nest.io.sede.lazy.LazyBinary.java
@Override public void init(ByteArrayRef bytes, int start, int length) { byte[] recv = new byte[length]; System.arraycopy(bytes.getData(), start, recv, 0, length); boolean arrayByteBase64 = Base64.isArrayByteBase64(recv); if (arrayByteBase64) { LOG.debug("Data not contains valid characters within the Base64 alphabet so " + "decoded the data."); }// w w w. j ava 2 s. c om byte[] decoded = arrayByteBase64 ? Base64.decodeBase64(recv) : recv; data.set(decoded, 0, decoded.length); }
From source file:com.bradmcevoy.http.http11.auth.DigestHelper.java
public DigestResponse calculateResponse(Auth auth, String expectedRealm, Method method) { // Check all required parameters were supplied (ie RFC 2069) if ((auth.getUser() == null) || (auth.getRealm() == null) || (auth.getNonce() == null) || (auth.getUri() == null)) { log.warn("missing params"); return null; }// ww w. j av a 2 s . co m // Check all required parameters for an "auth" qop were supplied (ie RFC 2617) Long nc; if ("auth".equals(auth.getQop())) { if ((auth.getNc() == null) || (auth.getCnonce() == null)) { log.warn("missing params: nc and/or cnonce"); return null; } nc = Long.parseLong(auth.getNc(), 16); // the nonce-count. hex value, must always increase } else { nc = null; } // Check realm name equals what we expected if (expectedRealm == null) throw new IllegalStateException("realm is null"); if (!expectedRealm.equals(auth.getRealm())) { log.warn("incorrect realm: resource: " + expectedRealm + " given: " + auth.getRealm()); return null; } // Check nonce was a Base64 encoded (as sent by DigestProcessingFilterEntryPoint) if (!Base64.isArrayByteBase64(auth.getNonce().getBytes())) { log.warn("nonce not base64 encoded"); return null; } log.debug("nc: " + auth.getNc()); // Decode nonce from Base64 // format of nonce is // base64(expirationTime + "" + md5Hex(expirationTime + "" + key)) String plainTextNonce = new String(Base64.decodeBase64(auth.getNonce().getBytes())); NonceValidity validity = nonceProvider.getNonceValidity(plainTextNonce, nc); // if( NonceValidity.INVALID.equals( validity ) ) { // log.debug( "invalid nonce: " + plainTextNonce ); // return null; // } else if( NonceValidity.EXPIRED.equals( validity ) ) { // log.debug( "expired nonce: " + plainTextNonce ); // // make this known so that we can add stale field to challenge // auth.setNonceStale( true ); // return null; // } DigestResponse resp = toDigestResponse(auth, method); return resp; }
From source file:io.milton.http.http11.auth.DigestHelper.java
public DigestResponse calculateResponse(Auth auth, String expectedRealm, Method method) { try {/*from ww w . j ava 2 s .c om*/ // Check all required parameters were supplied (ie RFC 2069) if ((auth.getUser() == null) || (auth.getRealm() == null) || (auth.getNonce() == null) || (auth.getUri() == null)) { log.warn("missing params"); return null; } // Check all required parameters for an "auth" qop were supplied (ie RFC 2617) Long nc; if ("auth".equals(auth.getQop())) { if ((auth.getNc() == null) || (auth.getCnonce() == null)) { log.warn("missing params: nc and/or cnonce"); return null; } nc = Long.parseLong(auth.getNc(), 16); // the nonce-count. hex value, must always increase } else { nc = null; } // Check realm name equals what we expected if (expectedRealm == null) throw new IllegalStateException("realm is null"); if (!expectedRealm.equals(auth.getRealm())) { log.warn("incorrect realm: resource: " + expectedRealm + " given: " + auth.getRealm()); return null; } // Check nonce was a Base64 encoded (as sent by DigestProcessingFilterEntryPoint) if (!Base64.isArrayByteBase64(auth.getNonce().getBytes("UTF-8"))) { log.warn("nonce not base64 encoded"); return null; } log.debug("nc: " + auth.getNc()); // Decode nonce from Base64 // format of nonce is // base64(expirationTime + "" + md5Hex(expirationTime + "" + key)) String plainTextNonce = new String(Base64.decodeBase64(auth.getNonce().getBytes("UTF-8"))); NonceValidity validity = nonceProvider.getNonceValidity(plainTextNonce, nc); // if( NonceValidity.INVALID.equals( validity ) ) { // log.debug( "invalid nonce: " + plainTextNonce ); // return null; // } else if( NonceValidity.EXPIRED.equals( validity ) ) { // log.debug( "expired nonce: " + plainTextNonce ); // // make this known so that we can add stale field to challenge // auth.setNonceStale( true ); // return null; // } DigestResponse resp = toDigestResponse(auth, method); return resp; } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex); } }
From source file:com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments.BodyPartAttachment.java
public synchronized InputStream getInputStream() throws Exception { if (data != null) return new ByteArrayInputStream(data); AttachmentEncoding encoding = getEncoding(); if (encoding == AttachmentEncoding.NONE) return bodyPart.getInputStream(); data = Tools.readAll(bodyPart.getInputStream(), Tools.READ_ALL).toByteArray(); if (encoding == AttachmentEncoding.BASE64) { if (Base64.isArrayByteBase64(data)) data = Tools.readAll(new ByteArrayInputStream(Base64.decodeBase64(data)), Tools.READ_ALL) .toByteArray();//from w w w . j av a 2 s . c o m else throw new Exception("Attachment content for part [" + getPart() + "] is not base64 encoded"); } else if (encoding == AttachmentEncoding.HEX) { data = Hex.decodeHex(new String(data).toCharArray()); } return new ByteArrayInputStream(data); }