Java Code Examples for org.apache.commons.codec.binary.Base64#isBase64()
The following examples show how to use
org.apache.commons.codec.binary.Base64#isBase64() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackendConfigManager.java From io2014-codelabs with Apache License 2.0 | 6 votes |
/** * Extracts data without prefix since data from the front end is based64-encoded and prefixed with * "data:application/x-pkcs12;base64,". * * @param base64String from client * @return extracted data without prefix */ private Text removeClientHeaderFromData(String base64String) { if (StringUtility.isNullOrEmpty(base64String)) { return null; } int index = base64String.indexOf(PKCS12_BASE64_PREFIX); if (index < 0) { return null; } String data = base64String.substring(index + PKCS12_BASE64_PREFIX.length()); if (Base64.isBase64(data)) { return new Text(data); } else { return null; } }
Example 2
Source File: Util.java From rest-client with Apache License 2.0 | 5 votes |
public static byte[] base64decodeByteArray(String base64Str) throws Base64Exception { if(!Base64.isBase64(base64Str)) { throw new Base64Exception("Provided string is not Base64 encoded"); } byte[] out = Base64.decodeBase64(base64Str); return out; }
Example 3
Source File: Base64DecodingProcessor.java From datacollector with Apache License 2.0 | 5 votes |
@Override protected Field processField(Record record, byte[] fieldData) throws OnRecordErrorException { if (!Base64.isBase64(fieldData)) { throw new OnRecordErrorException(DataFormatErrors.DATA_FORMAT_302, record.toString()); } return Field.create(Base64.decodeBase64(fieldData)); }
Example 4
Source File: StoredConfigService.java From sakai with Educational Community License v2.0 | 5 votes |
private Object deSerializeValue(String value, String type, boolean secured) throws IllegalClassException { if (value == null || type == null) { return null; } String string; if (secured) { // sanity check should be Base64 encoded if (Base64.isBase64(value)) { string = textEncryptor.decrypt(value); } else { log.warn("Invalid value found attempting to decrypt a secured property, check your secured properties"); string = value; } } else { string = value; } Object obj; if (ServerConfigurationService.TYPE_STRING.equals(type)) { obj = string; } else if (ServerConfigurationService.TYPE_INT.equals(type)) { obj = Integer.valueOf(string); } else if (ServerConfigurationService.TYPE_BOOLEAN.equals(type)) { obj = Boolean.valueOf(string); } else if (ServerConfigurationService.TYPE_ARRAY.equals(type)) { obj = string.split(HibernateConfigItem.ARRAY_SEPARATOR); } else { throw new IllegalClassException("deSerializeValue() invalid TYPE, while deserializing"); } return obj; }
Example 5
Source File: ValidatingBase64InputStream.java From nifi with Apache License 2.0 | 5 votes |
@Override public int read(byte[] b) throws IOException { int numRead = super.read(b); if (numRead > 0) { byte[] copy = b; if (numRead < b.length) { // isBase64 checks the whole length of byte[], we need to limit it to numRead copy = Arrays.copyOf(b, numRead); } if (!Base64.isBase64(copy)) { throw new IOException("Data is not base64 encoded."); } } return numRead; }
Example 6
Source File: ValidatingBase64InputStream.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override public int read(byte[] b, int offset, int len) throws IOException { int numRead = super.read(b, offset, len); if (numRead > 0) { byte[] copy = b; if (numRead < b.length) { // isBase64 checks the whole length of byte[], we need to limit it to numRead copy = Arrays.copyOf(b, numRead); } if (!Base64.isBase64(copy)) { throw new IOException("Data is not base64 encoded."); } } return numRead; }
Example 7
Source File: ValidatingBase64InputStream.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override public int read(byte[] b) throws IOException { int numRead = super.read(b); if (numRead > 0) { byte[] copy = b; if (numRead < b.length) { // isBase64 checks the whole length of byte[], we need to limit it to numRead copy = Arrays.copyOf(b, numRead); } if (!Base64.isBase64(copy)) { throw new IOException("Data is not base64 encoded."); } } return numRead; }
Example 8
Source File: ValidatingBase64InputStream.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override public int read() throws IOException { int data = super.read(); if (!Base64.isBase64((byte) data)) { throw new IOException("Data is not base64 encoded."); } return super.read(); }
Example 9
Source File: ValidatingBase64InputStream.java From nifi with Apache License 2.0 | 5 votes |
@Override public int read(byte[] b, int offset, int len) throws IOException { int numRead = super.read(b, offset, len); if (numRead > 0) { byte[] copy = b; if (numRead < b.length) { // isBase64 checks the whole length of byte[], we need to limit it to numRead copy = Arrays.copyOf(b, numRead); } if (!Base64.isBase64(copy)) { throw new IOException("Data is not base64 encoded."); } } return numRead; }
Example 10
Source File: ClientSideCEncryptionStrategy.java From nifi with Apache License 2.0 | 5 votes |
@Override public ValidationResult validateKey(String keyValue) { if (StringUtils.isBlank(keyValue)) { return new ValidationResult.Builder() .subject("Key Material") .valid(false) .explanation("it is empty") .build(); } byte[] keyMaterial; try { if (!Base64.isBase64(keyValue)) { throw new Exception(); } keyMaterial = Base64.decodeBase64(keyValue); } catch (Exception e) { return new ValidationResult.Builder() .subject("Key Material") .valid(false) .explanation("it is not in Base64 encoded form") .build(); } if (!(keyMaterial.length == 32 || keyMaterial.length == 24 || keyMaterial.length == 16)) { return new ValidationResult.Builder() .subject("Key Material") .valid(false) .explanation("it is not a Base64 encoded AES-256, AES-192 or AES-128 key") .build(); } return new ValidationResult.Builder().valid(true).build(); }
Example 11
Source File: ScooldUtils.java From scoold with Apache License 2.0 | 5 votes |
public String base64DecodeScript(String encodedScript) { if (StringUtils.isBlank(encodedScript)) { return ""; } try { String decodedScript = Base64.isBase64(encodedScript) ? Utils.base64dec(encodedScript) : ""; return StringUtils.isBlank(decodedScript) ? encodedScript : decodedScript; } catch (Exception e) { return encodedScript; } }
Example 12
Source File: JsUtil.java From ctsms with GNU Lesser General Public License v2.1 | 5 votes |
public static String decodeBase64(String base64String) { if (base64String != null && base64String.length() > 0 && Base64.isBase64(base64String)) { try { return new String(Base64.decodeBase64(base64String), CommonUtil.BASE64_CHARSET); } catch (UnsupportedEncodingException e) { } } return ""; }
Example 13
Source File: ViewableDownloadBubble.java From MaximoForgeViewerPlugin with Eclipse Public License 1.0 | 4 votes |
public Result viewableDownload( String derivitiveURN, String dirName ) throws IOException, URISyntaxException { String urn; String base64urn; if( Base64.isBase64(derivitiveURN) ) { urn = new String( Base64.decodeBase64( derivitiveURN ) ); base64urn = derivitiveURN; } else { urn = derivitiveURN; base64urn = new String( Base64.encodeBase64URLSafe( derivitiveURN.getBytes() )); } ResultViewerService result = _service.viewableQuery( urn ); if( result.isError() ) { return result; } List<String> files = new LinkedList<String>(); result.listDerivativeFiles( files ); Iterator<String> itr = files.iterator(); while( itr.hasNext() ) { String fileName = itr.next(); Result dr = _service.viewableDownload( base64urn, dirName, fileName ); if( dr.isError() ) { System.out.println( dr.toString() ); } else { System.out.println( dirName + "/" + fileName );; } } return result; }
Example 14
Source File: ApacheCommonsUtils.java From dss with GNU Lesser General Public License v2.1 | 4 votes |
@Override public boolean isBase64Encoded(String base64String) { return Base64.isBase64(base64String); }
Example 15
Source File: StringUtil.java From peer-os with Apache License 2.0 | 4 votes |
public static boolean isBase64( String str ) { return Base64.isBase64( str ); }
Example 16
Source File: Base64Validator.java From cloudbreak with Apache License 2.0 | 4 votes |
@Override public boolean isValid(String value, ConstraintValidatorContext context) { return !StringUtils.hasLength(value) || Base64.isBase64(value); }
Example 17
Source File: Base64BinaryType.java From org.hl7.fhir.core with Apache License 2.0 | 2 votes |
/** * Checks if the passed in String is a valid {@link Base64} encoded String. Will throw a {@link DataFormatException} if not * formatted correctly. * * @param toCheck {@link String} to check if valid {@link Base64} * @throws DataFormatException */ public void checkValidBase64(String toCheck) throws DataFormatException { if (!Base64.isBase64(toCheck.getBytes())) { throw new DataFormatException(""); } }
Example 18
Source File: Base64BinaryType.java From org.hl7.fhir.core with Apache License 2.0 | 2 votes |
/** * Checks if the passed in String is a valid {@link Base64} encoded String. Will throw a {@link DataFormatException} if not * formatted correctly. * * @param toCheck {@link String} to check if valid {@link Base64} * @throws DataFormatException */ public void checkValidBase64(String toCheck) throws DataFormatException { if (!Base64.isBase64(toCheck.getBytes())) { throw new DataFormatException(""); } }
Example 19
Source File: Base64BinaryType.java From org.hl7.fhir.core with Apache License 2.0 | 2 votes |
/** * Checks if the passed in String is a valid {@link Base64} encoded String. Will throw a {@link DataFormatException} if not * formatted correctly. * * @param toCheck {@link String} to check if valid {@link Base64} * @throws DataFormatException */ public void checkValidBase64(String toCheck) throws DataFormatException { if (!Base64.isBase64(toCheck.getBytes())) { throw new DataFormatException(""); } }
Example 20
Source File: Base64BinaryType.java From org.hl7.fhir.core with Apache License 2.0 | 2 votes |
/** * Checks if the passed in String is a valid {@link Base64} encoded String. Will throw a {@link DataFormatException} if not * formatted correctly. * * @param toCheck {@link String} to check if valid {@link Base64} * @throws DataFormatException */ public void checkValidBase64(String toCheck) throws DataFormatException { if (!Base64.isBase64(toCheck.getBytes())) { throw new DataFormatException(""); } }