List of usage examples for org.apache.commons.codec.binary Base64 isBase64
public static boolean isBase64(final byte[] arrayOctet)
From source file:base64test.Base64Test.java
/** * @param args the command line arguments */// www. java 2 s. c o m public static void main(String[] args) { try { if (!Base64.isBase64(args[0])) { throw new Exception("Arg 1 is not a Base64 string!"); } else { String decodedBase64String = new String(Base64.decodeBase64(args[0])); File tempFile = File.createTempFile("base64Test", ".tmp"); tempFile.deleteOnExit(); FileWriter fw = new FileWriter(tempFile, false); PrintWriter pw = new PrintWriter(fw); pw.write(decodedBase64String); pw.close(); String fileType = getFileType(tempFile.toPath()); System.out.println(fileType); System.in.read(); } } catch (Exception e) { System.err.println(e.getMessage()); } }
From source file:com.mnr.java.intellij.idea.plugin.base64helper.DecoderPopupItem.java
@Override public Boolean isSelectable(String selectedText) { return super.isSelectable(selectedText) && Base64.isBase64(selectedText); }
From source file:com.sap.core.odata.core.edm.EdmBinary.java
private static boolean validateLiteral(final String value, final EdmLiteralKind literalKind) { return literalKind == EdmLiteralKind.URI ? value.matches("(?:X|binary)'(?:\\p{XDigit}{2})*'") : Base64.isBase64(value); }
From source file:com.streamsets.pipeline.stage.processor.base64.Base64DecodingProcessor.java
@Override protected Field processField(Record record, byte[] fieldData) throws OnRecordErrorException { if (!Base64.isBase64(fieldData)) { throw new OnRecordErrorException(DataFormatErrors.DATA_FORMAT_302, record.toString()); }//w w w . j a v a 2 s . c o m return Field.create(Base64.decodeBase64(fieldData)); }
From source file:com.bconomy.autobit.Encryption.java
public static String decrypt(String cyphertext) { if (cyphertext == null || cyphertext.equals("") || !Base64.isBase64(cyphertext)) return ""; try {/*from ww w. j av a 2 s . c o m*/ return new String(decrypt(Base64.decodeBase64(cyphertext)), "UTF-8"); } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); } return ""; }
From source file:com.netflix.spinnaker.orca.pipelinetemplate.tasks.v2.CreateV2PipelineTemplateTask.java
@SuppressWarnings("unchecked") @Override/*w w w. jav a 2 s .c om*/ public TaskResult execute(Stage stage) { if (front50Service == null) { throw new UnsupportedOperationException( "Front50 is not enabled, no way to save pipeline templates. Fix this by setting front50.enabled: true"); } if (!stage.getContext().containsKey("pipelineTemplate")) { throw new IllegalArgumentException("Missing required task parameter (pipelineTemplate)"); } if (!(stage.getContext().get("pipelineTemplate") instanceof String) || !Base64.isBase64((String) stage.getContext().get("pipelineTemplate"))) { throw new IllegalArgumentException( "'pipelineTemplate' context key must be a base64-encoded string: Ensure you're on the most recent version of gate"); } V2PipelineTemplate pipelineTemplate = stage.decodeBase64("/pipelineTemplate", V2PipelineTemplate.class, pipelineTemplateObjectMapper); validate(pipelineTemplate); Response response = front50Service.saveV2PipelineTemplate((Map<String, Object>) stage .decodeBase64("/pipelineTemplate", Map.class, pipelineTemplateObjectMapper)); Map<String, Object> outputs = new HashMap<>(); outputs.put("notification.type", "createpipelinetemplate"); outputs.put("pipelineTemplate.id", pipelineTemplate.getId()); if (response.getStatus() == HttpStatus.OK.value()) { return new TaskResult(ExecutionStatus.SUCCEEDED, outputs); } return new TaskResult(ExecutionStatus.TERMINAL, outputs); }
From source file:com.netflix.spinnaker.orca.pipelinetemplate.tasks.v2.UpdateV2PipelineTemplateTask.java
@SuppressWarnings("unchecked") @Override/*from ww w .ja v a 2 s . c om*/ public TaskResult execute(Stage stage) { if (front50Service == null) { throw new UnsupportedOperationException( "Front50 is not enabled, no way to save pipeline templates. Fix this by setting front50.enabled: true"); } if (!stage.getContext().containsKey("pipelineTemplate")) { throw new IllegalArgumentException("Missing required task parameter (pipelineTemplate)"); } if (!(stage.getContext().get("pipelineTemplate") instanceof String) || !Base64.isBase64((String) stage.getContext().get("pipelineTemplate"))) { throw new IllegalArgumentException( "'pipelineTemplate' context key must be a base64-encoded string: Ensure you're on the most recent version of gate"); } List<String> missingParams = new ArrayList<>(); if (!stage.getContext().containsKey("id")) { missingParams.add("id"); } if (!stage.getContext().containsKey("pipelineTemplate")) { missingParams.add("pipelineTemplate"); } if (!missingParams.isEmpty()) { throw new IllegalArgumentException("Missing required task parameter (" + StringUtils.arrayToCommaDelimitedString(missingParams.toArray()) + ")"); } V2PipelineTemplate pipelineTemplate = stage.decodeBase64("/pipelineTemplate", V2PipelineTemplate.class, pipelineTemplateObjectMapper); validate(pipelineTemplate); // TODO(jacobkiefer): move this to an update call to front50. Response response = front50Service.updateV2PipelineTemplate((String) stage.getContext().get("id"), (Map<String, Object>) stage.decodeBase64("/pipelineTemplate", Map.class)); Map<String, Object> outputs = new HashMap<>(); outputs.put("notification.type", "updatepipelinetemplate"); outputs.put("pipelineTemplate.id", pipelineTemplate.getId()); if (response.getStatus() == HttpStatus.OK.value()) { return new TaskResult(ExecutionStatus.SUCCEEDED, outputs); } return new TaskResult(ExecutionStatus.TERMINAL, outputs); }
From source file:net.bryansaunders.jee6divelog.util.SecurityUtilsTest.java
/** * Test Method for Generate REST API Key. *///from w w w . ja v a2 s. c o m @Test public void testGenerateApiKey() { final String apiKey = SecurityUtils.generateRestApiKey(); assertNotNull(apiKey); assertTrue(apiKey.length() >= 32); assertTrue(Base64.isBase64(apiKey)); }
From source file:energy.usef.core.service.business.MessageEncryptionService.java
/** * Unseal a message (Base64 encoded) using a Base64 public key (256 bits decoded). * * @param sealedMessage - {@link String} sealed message * @param b64PublicKey - {@link String} base64 encoded public key (256 bits decoded) * @return a UTF-8 encoded {@link String} * @throws BusinessException/*from w w w.j a v a 2 s. c o m*/ */ public String verifyMessage(byte[] sealedMessage, String b64PublicKey) throws BusinessException { if (sealedMessage == null) { return null; } if (!Base64.isBase64(sealedMessage)) { throw new BusinessException(MessageEncryptionError.EXPECTED_BASE64_SEALED_MESSAGE); } requireNonNull(b64PublicKey); if (!Base64.isBase64(b64PublicKey)) { throw new BusinessException(MessageEncryptionError.EXPECTED_BASE64_PUBLIC_KEY); } byte[] publicKey = decodeBase64(b64PublicKey); verifyPublicKeyLength(publicKey); return verifyMessage(decodeBase64(sealedMessage), publicKey); }
From source file:edu.tamu.tcat.crypto.spongycastle.PBKDF2Impl.java
@Override protected boolean checkHash(byte[] password, String saltStr, String outputStr, DigestType digest, int rounds) { if (!Base64.isBase64(saltStr) || !Base64.isBase64(outputStr)) return false; byte[] salt = Base64.decodeBase64(saltStr); byte[] output = Base64.decodeBase64(outputStr); int outputSize = DigestTypeMap.getDigest(digest).getDigestSize(); if (output.length != outputSize) return false; PBKDF2Impl pbkdf2 = new PBKDF2Impl(digest); byte[] candidate = pbkdf2.deriveKey(password, salt, rounds, outputSize); return Arrays.equals(candidate, output); }