List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64String
public static String encodeBase64String(final byte[] binaryData)
From source file:com.consol.citrus.functions.core.ReadFileResourceFunction.java
@Override public String execute(List<String> parameterList, TestContext context) { if (CollectionUtils.isEmpty(parameterList)) { throw new InvalidFunctionUsageException("Missing file path function parameter"); }/*from w w w .j av a 2 s.com*/ boolean base64 = parameterList.size() > 1 ? Boolean.valueOf(parameterList.get(1)) : false; try { if (base64) { return Base64.encodeBase64String(FileCopyUtils.copyToByteArray( FileUtils.getFileResource(parameterList.get(0), context).getInputStream())); } else { return context.replaceDynamicContentInString( FileUtils.readToString(FileUtils.getFileResource(parameterList.get(0), context))); } } catch (IOException e) { throw new CitrusRuntimeException("Failed to read file", e); } }
From source file:de.tntinteractive.portalsammler.engine.CryptoHelper.java
public static String keyToString(final byte[] key) { return Base64.encodeBase64String(key); }
From source file:net.algem.util.CommonDao.java
public String findPhoto(int idper) throws DataAccessException { String query = "SELECT photo FROM " + PHOTO_TABLE + " WHERE idper = ?"; byte[] data = jdbcTemplate.queryForObject(query, new RowMapper<byte[]>() { @Override// w ww . j av a 2 s. c o m public byte[] mapRow(ResultSet rs, int i) throws SQLException { return rs.getBytes(1); } }, idper); return Base64.encodeBase64String(data); }
From source file:com.github.woki.payments.adyen.action.CSEUtil.java
static String encrypt(final Cipher aesCipher, final Cipher rsaCipher, final String plainText) throws BadPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException { SecretKey aesKey = aesKey(256); byte[] iv = iv(CSE_RANDOM, 12); aesCipher.init(Cipher.ENCRYPT_MODE, aesKey, new IvParameterSpec(iv)); byte[] encrypted = aesCipher.doFinal(plainText.getBytes()); byte[] result = new byte[iv.length + encrypted.length]; System.arraycopy(iv, 0, result, 0, iv.length); System.arraycopy(encrypted, 0, result, iv.length, encrypted.length); byte[] encryptedAESKey; try {/* w ww . java2 s .c o m*/ encryptedAESKey = rsaCipher.doFinal(aesKey.getEncoded()); } catch (ArrayIndexOutOfBoundsException e) { throw new InvalidKeyException(e.getMessage()); } return String.format("%s%s%s%s%s%s", CSE_PREFIX, CSE_VERSION, CSE_SEPARATOR, Base64.encodeBase64String(encryptedAESKey), CSE_SEPARATOR, Base64.encodeBase64String(result)); }
From source file:com.shigengyu.hyperion.core.WorkflowContextBinarySerializer.java
@Override public String serialize(WorkflowContext workflowContext) { return Base64.encodeBase64String(SerializationUtils.serialize(workflowContext)); }
From source file:com.connorbrezinsky.msg.security.Hash.java
private static String hash(String password, byte[] salt) throws Exception { if (password == null || password.length() == 0) throw new IllegalArgumentException("Empty passwords are not supported."); SecretKeyFactory f = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); SecretKey key = f.generateSecret(new PBEKeySpec(password.toCharArray(), salt, iterations, desiredKeyLen)); return Base64.encodeBase64String(key.getEncoded()); }
From source file:de.qaware.campus.secpro.web.passwords.SecurePasswordsTest.java
@BeforeMethod public void setUp() throws Exception { String saltBase64 = Base64.encodeBase64String(new byte[] { 's', 'a', 'l', 't' }); salt = Salt.fromBase64(saltBase64);/*w w w. j a v a 2 s . c om*/ System.setProperty("de.qaware.campus.secpro.password", MASTER_PASSWORD); securePasswords = new SecurePasswords(MasterPassword.INSTANCE); securePasswords.initialize(); }
From source file:eu.europa.esig.dss.validation.TimestampReference.java
public TimestampReference(final String signatureId) { if (signatureId == null) { throw new NullPointerException(); }/*from w w w. jav a 2s .c o m*/ this.signatureId = signatureId; this.digestAlgorithm = DigestAlgorithm.SHA1.name(); this.digestValue = Base64.encodeBase64String(DSSUtils.digest(DigestAlgorithm.SHA1, signatureId.getBytes())); this.category = TimestampReferenceCategory.SIGNATURE; }
From source file:com.spectralogic.ds3client.utils.hashing.Md5Hash.java
public String toBase64String() { return Base64.encodeBase64String(this.hash); }
From source file:com.consol.citrus.validation.text.BinaryBase64MessageValidatorTest.java
@Test public void testBinaryBase64ValidationNoBinaryData() { Message receivedMessage = new DefaultMessage("SGVsbG8gV29ybGQh"); Message controlMessage = new DefaultMessage(Base64.encodeBase64String("Hello World!".getBytes())); ValidationContext validationContext = new DefaultValidationContext(); validator.validateMessagePayload(receivedMessage, controlMessage, validationContext, context); }