List of usage examples for org.apache.commons.codec.binary Base64 decodeBase64
public static byte[] decodeBase64(final byte[] base64Data)
From source file:com.vmware.o11n.plugin.crypto.service.CryptoEncodingService.java
/** * * @param b64data/*from w w w.j a v a 2s . co m*/ * @return */ public String base64Decode(String b64data) { String decoded = new String(Base64.decodeBase64(b64data), StandardCharsets.UTF_8); return decoded; }
From source file:com.amazon.aws.demo.anonymous.sqs.SqsMessageBody.java
private void updateUi() { loadingText.setText(messageId);//from ww w . j a v a 2 s . c o m String message = SimpleQueue.getMessageBody(messageIndex); String decodedMessage = new String(Base64.decodeBase64(message.getBytes())); if (decodedMessage.charAt(0) == '{' && decodedMessage.endsWith("}")) bodyText.setText(decodedMessage); else bodyText.setText(message); loadingText.setTextSize(16); }
From source file:com.POLIS.licensing.common.license.AbstractSerializationBasedLicenseFactory.java
@Override public T loadLicense(String data, PrivateKey senderEncryptionKey, PublicKey senderSignatureKey) throws BadLicenseException, SystemStateException, OperationException { byte[] decodedLicense; decodedLicense = Base64.decodeBase64(data); byte[] encryptedSymKey = new byte[symkeySize]; byte[] encryptedLicense = new byte[decodedLicense.length - symkeySize]; byte[] decryptedSymKey; byte[] decryptedLicense; Key symkey;/*from w w w . java 2s. co m*/ System.arraycopy(decodedLicense, 0, encryptedSymKey, 0, symkeySize); System.arraycopy(decodedLicense, symkeySize, encryptedLicense, 0, decodedLicense.length - symkeySize); Cipher asymetriccipher; try { asymetriccipher = Cipher.getInstance(AbstractSerializationBasedLicense.asymmetricEncoding, AbstractSerializationBasedLicense.provider); asymetriccipher.init(Cipher.DECRYPT_MODE, senderEncryptionKey); } catch (NoSuchAlgorithmException | NoSuchProviderException | /*InvalidKeySpecException |*/ NoSuchPaddingException | InvalidKeyException ex) { throw new SystemStateException("The specified encryption provider or algorithm was not found", ex); } try { decryptedSymKey = asymetriccipher.doFinal(encryptedSymKey); symkey = new SecretKeySpec(decryptedSymKey, "AES"); } catch (IllegalBlockSizeException | BadPaddingException ex) { throw new SystemStateException("Could not decode the symkey for the license", ex); } Cipher symmetriccipher; try { symmetriccipher = Cipher.getInstance(AbstractSerializationBasedLicense.symmetricEncoding, AbstractSerializationBasedLicense.provider); symmetriccipher.init(Cipher.DECRYPT_MODE, symkey); } catch (NoSuchAlgorithmException | NoSuchProviderException | /*InvalidKeySpecException |*/ NoSuchPaddingException | InvalidKeyException ex) { throw new SystemStateException("The specified encryption provider or algorithm was not found", ex); } try { decryptedLicense = symmetriccipher.doFinal(encryptedLicense); } catch (IllegalBlockSizeException | BadPaddingException ex) { throw new SystemStateException("Could not encode to base64", ex); } T license; try { license = getDeserializedObject(decryptedLicense); } catch (IOException | ClassNotFoundException ex) { throw new SystemStateException("An error occurred while reading the license from the input byte array.", ex); } if (license.verifyLicense(senderSignatureKey)) { return license; } else throw new BadLicenseException(license, "The license could not be verified with the specified signature decryption key"); }
From source file:com.lecaddyfute.utils.security.AESCrypto.java
public static String decrypt(String encryptedData) throws Exception { Key key = generateKey();/*from w w w . j a va 2 s. co m*/ Cipher c = Cipher.getInstance(ALGO); c.init(Cipher.DECRYPT_MODE, key); byte[] decordedValue = Base64.decodeBase64(encryptedData.getBytes()); byte[] decValue = c.doFinal(decordedValue); String decryptedValue = new String(decValue); return decryptedValue; }
From source file:com.oneops.ecv.auth.AuthUtil.java
public boolean authenticate(String authString) { if (authString == null || "".equals(authString.trim())) { return false; }//from w ww .j ava 2 s.c om String[] authTokens = authString.split("\\s"); for (String token : authTokens) { if (HTTP_REQUEST_HEADER_AUTH_BASIC_VAL_PREFIX.equals(token)) continue; String credential = new String(Base64.decodeBase64(token)); if (credential.indexOf(HTTP_REQUEST_HEADER_AUTH_BASIC_VAL_SEPARATOR) != -1) { String[] credentials = credential.split(":"); if (credentials.length != 2) return false; String requestUserName = credentials[0]; String requestUserCred = credentials[1]; if (user.equals(requestUserName) && secret.equals(requestUserCred)) { return true; } } } return false; }
From source file:asia.stampy.common.serialization.SerializationUtils.java
/** * Deserialize base64.//from w w w .j a va 2s . c o m * * @param s * the s * @return the object * @throws IOException * Signals that an I/O exception has occurred. * @throws ClassNotFoundException * the class not found exception */ public static Object deserializeBase64(String s) throws IOException, ClassNotFoundException { DESERIALIZE_LOCK.lock(); try { byte[] bytes = Base64.decodeBase64(s); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes)); return ois.readObject(); } finally { DESERIALIZE_LOCK.unlock(); } }
From source file:com.mobileman.kuravis.core.util.security.SecurityUtils.java
/** * Checks whether given plaintext password corresponds to a stored salted * hash of the password.//w ww . j av a 2s .com * * @param password * @param stored * @return true if both passwpord matches * @throws Exception */ public static boolean check(String password, String stored) throws Exception { String[] saltAndPass = stored.split("\\$"); if (saltAndPass.length != 2) return false; String hashOfInput = hash(password, Base64.decodeBase64(saltAndPass[0])); return hashOfInput.equals(saltAndPass[1]); }
From source file:com.consol.citrus.functions.core.DecodeBase64Function.java
/** * {@inheritDoc}/*from w w w . j a v a 2s. c o m*/ */ public String execute(List<String> parameterList, TestContext context) { if (CollectionUtils.isEmpty(parameterList) || parameterList.size() < 1) { throw new InvalidFunctionUsageException("Invalid function parameter usage! Missing parameters!"); } String charset = "UTF-8"; if (parameterList.size() > 1) { charset = parameterList.get(1); } try { return new String(Base64.decodeBase64(parameterList.get(0)), charset); } catch (UnsupportedEncodingException e) { throw new CitrusRuntimeException("Unsupported character encoding", e); } }
From source file:com.aast.encrypt.EncryptManager.java
public static String decryptAES(String key, String encrypted) { try {//from ww w . j a v a 2s . com byte[] keyBytes = getKeyFromString(key); IvParameterSpec iv = new IvParameterSpec(keyBytes); SecretKeySpec skeySpec = new SecretKeySpec(keyBytes, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv); byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted)); return new String(original); } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:com.splicemachine.compactions.CompactionRecordReader.java
@Override public void initialize(InputSplit split, TaskAttemptContext context) { String fileString = conf.get(MRConstants.COMPACTION_FILES); files = SerializationUtils.deserialize(Base64.decodeBase64(fileString)); currentKey = new Integer(0); }