List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64
public static byte[] encodeBase64(final byte[] binaryData)
From source file:com.ultrapower.eoms.common.plugin.ecside.util.ECSideUtils.java
public static String encodeFileName(String fileName, String agent) throws UnsupportedEncodingException{ String codedfilename = null; fileName=fileName.replaceAll("\n|\r", " ").trim(); if (null != agent && -1 != agent.indexOf("MSIE")) { codedfilename = URLEncoder.encode(fileName, "UTF8"); // String prefix = fileName.lastIndexOf(".") != -1 ? fileName // .substring(0, fileName.lastIndexOf(".")) : fileName; // String extension = fileName.lastIndexOf(".") != -1 ? fileName // .substring(fileName.lastIndexOf(".")) : ""; // int limit = 150 - extension.length(); // if (codedfilename.length() > limit) { // codedfilename = java.net.URLEncoder.encode(prefix.substring(0, Math.min( // prefix.length(), limit / 9)), "UTF-8"); // codedfilename = codedfilename + extension; // }/*from w ww. jav a 2 s . c o m*/ } else if (null != agent && -1 != agent.indexOf("Mozilla")) { codedfilename = "=?UTF-8?B?"+(new String(Base64.encodeBase64(fileName.getBytes("UTF-8"))))+"?="; } else { codedfilename = fileName; } return codedfilename; }
From source file:com.soctec.soctec.utils.Encryptor.java
/** * Encrypts and Base64 encodes a string// w w w.j av a2 s. c o m * @param str the string to encrypt * @return a encrypted and Base64 encoded string */ public String encrypt(String str) { byte[] enc = new byte[0]; try { enc = ecipher.doFinal(str.getBytes("UTF-8")); } catch (IllegalBlockSizeException | BadPaddingException | UnsupportedEncodingException e) { e.printStackTrace(); } return new String(Base64.encodeBase64(enc)); }
From source file:it.geosolutions.geostore.core.security.password.GeoStoreDigestPasswordEncoder.java
@Override protected CharArrayPasswordEncoder createCharEncoder() { return new CharArrayPasswordEncoder() { StandardByteDigester digester = new StandardByteDigester(); {//from w w w .j a v a2 s .com digester.setAlgorithm("SHA-256"); digester.setIterations(100000); digester.setSaltSizeBytes(16); digester.initialize(); } @Override public String encodePassword(char[] rawPass, Object salt) { return new String(Base64.encodeBase64(digester.digest(toBytes(rawPass)))); } @Override public boolean isPasswordValid(String encPass, char[] rawPass, Object salt) { return digester.matches(toBytes(rawPass), Base64.decodeBase64(encPass.getBytes())); } }; }
From source file:com.monitor.baseservice.utils.XCodeUtil.java
public static String base16ToBase64(String str) { int length = str.length() / 2; byte[] data = new byte[length]; for (int i = 0; i < length; i++) { String tmp = str.substring(i * 2, (i + 1) * 2); int c = Integer.parseInt(tmp, 16); data[i] = (byte) c; }// www . j a v a2 s . c o m byte[] code = Base64.encodeBase64(data); return new String(code); }
From source file:ch.cyberduck.core.analytics.QloudstatAnalyticsProvider.java
@Override public DescriptiveUrl getSetup(final String hostname, final Scheme method, final Path container, final Credentials credentials) { final String setup = String.format("provider=%s,protocol=%s,endpoint=%s,key=%s,secret=%s", hostname, method.name(), containerService.getContainer(container).getName(), credentials.getUsername(), credentials.getPassword());/* w ww . ja v a 2 s . c o m*/ final String encoded; try { encoded = this.encode(new String(Base64.encodeBase64(setup.getBytes("UTF-8")), "UTF-8")); } catch (UnsupportedEncodingException e) { return null; } final String formatted = String.format("%s?setup=%s", target, encoded); if (log.isInfoEnabled()) { log.info(String.format("Setup URL %s", formatted)); } return new DescriptiveUrl(URI.create(formatted), DescriptiveUrl.Type.analytics); }
From source file:com.the_incognito.darry.incognitochatmessengertest.BouncyCastleImplementation.java
public static String encrypt(String key, String toEncrypt) throws Exception { Key skeySpec = generateKeySpec(key); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", new BouncyCastleProvider()); String abc = RandomStringUtils.randomAlphanumeric(16); System.out.println(abc);/* w ww.ja v a 2 s. c o m*/ byte[] ivBytes = abc.getBytes(); IvParameterSpec ivSpec = new IvParameterSpec(ivBytes); cipher.init(Cipher.ENCRYPT_MODE, skeySpec, ivSpec); byte[] encrypted = cipher.doFinal(toEncrypt.getBytes()); byte[] encryptedValue; encryptedValue = Base64.encodeBase64(encrypted); String result = new String(); result += new String(encryptedValue); result = abc + result; System.out.println(result); return result; }
From source file:net.bioclipse.encryption.Encrypter.java
public String encrypt(String plaintext) { SecretKeyFactory keyFac;// w w w .j a va2 s .c om SecretKey pbeKey; Cipher pbeCipher; try { keyFac = SecretKeyFactory.getInstance(METHOD); pbeKey = keyFac.generateSecret(pbeKeySpec); pbeCipher = Cipher.getInstance(METHOD); pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec); return new String(Base64.encodeBase64(pbeCipher.doFinal(plaintext.getBytes()))); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException(e); } catch (InvalidKeySpecException e) { throw new IllegalStateException(e); } catch (NoSuchPaddingException e) { throw new IllegalStateException(e); } catch (InvalidKeyException e) { throw new IllegalStateException(e); } catch (InvalidAlgorithmParameterException e) { throw new IllegalStateException(e); } catch (IllegalBlockSizeException e) { throw new IllegalStateException(e); } catch (BadPaddingException e) { throw new IllegalStateException(e); } }
From source file:com.rackspacecloud.blueflood.io.serializers.astyanax.GaugeRollupSerializerTest.java
@Test public void testSerializerDeserializerV1() throws Exception { BluefloodGaugeRollup gauge1 = BluefloodGaugeRollup.buildFromRawSamples( Rollups.asPoints(SimpleNumber.class, System.currentTimeMillis(), 300, new SimpleNumber(10L))); BluefloodGaugeRollup gauge2 = BluefloodGaugeRollup.buildFromRawSamples(Rollups.asPoints(SimpleNumber.class, System.currentTimeMillis() - 100, 300, new SimpleNumber(1234567L))); BluefloodGaugeRollup gauge3 = BluefloodGaugeRollup.buildFromRawSamples(Rollups.asPoints(SimpleNumber.class, System.currentTimeMillis() - 200, 300, new SimpleNumber(10.4D))); BluefloodGaugeRollup gaugesRollup = BluefloodGaugeRollup.buildFromGaugeRollups(Rollups .asPoints(BluefloodGaugeRollup.class, System.currentTimeMillis(), 300, gauge1, gauge2, gauge3)); Assert.assertEquals(3, gaugesRollup.getCount()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(Base64.encodeBase64(Serializers.gaugeRollupInstance.toByteBuffer(gauge1).array())); baos.write("\n".getBytes()); baos.write(Base64.encodeBase64(Serializers.gaugeRollupInstance.toByteBuffer(gauge2).array())); baos.write("\n".getBytes()); baos.write(Base64.encodeBase64(Serializers.gaugeRollupInstance.toByteBuffer(gauge3).array())); baos.write("\n".getBytes()); baos.write(Base64.encodeBase64(Serializers.gaugeRollupInstance.toByteBuffer(gaugesRollup).array())); baos.write("\n".getBytes()); baos.close();/* ww w. ja va 2 s.co m*/ BufferedReader reader = new BufferedReader( new InputStreamReader(new ByteArrayInputStream(baos.toByteArray()))); ByteBuffer bb = ByteBuffer.wrap(Base64.decodeBase64(reader.readLine().getBytes())); BluefloodGaugeRollup deserializedGauge1 = Serializers.serializerFor(BluefloodGaugeRollup.class) .fromByteBuffer(bb); Assert.assertEquals(gauge1, deserializedGauge1); bb = ByteBuffer.wrap(Base64.decodeBase64(reader.readLine().getBytes())); BluefloodGaugeRollup deserializedGauge2 = Serializers.serializerFor(BluefloodGaugeRollup.class) .fromByteBuffer(bb); Assert.assertEquals(gauge2, deserializedGauge2); bb = ByteBuffer.wrap(Base64.decodeBase64(reader.readLine().getBytes())); BluefloodGaugeRollup deserializedGauge3 = Serializers.serializerFor(BluefloodGaugeRollup.class) .fromByteBuffer(bb); Assert.assertEquals(gauge3, deserializedGauge3); bb = ByteBuffer.wrap(Base64.decodeBase64(reader.readLine().getBytes())); BluefloodGaugeRollup deserializedGauge4 = Serializers.serializerFor(BluefloodGaugeRollup.class) .fromByteBuffer(bb); Assert.assertEquals(gaugesRollup, deserializedGauge4); Assert.assertFalse(deserializedGauge1.equals(deserializedGauge2)); }
From source file:net.leadware.commons.codec.plugin.base64.Base64Mojo.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { // Encodage// w ww. ja va 2 s . c o m String encoded = new String(Base64.encodeBase64(inputValue.getBytes())); // Affichage getLog().debug("encoded identity ==> " + encoded); // Positionnement dans la variable resultat project.getProperties().setProperty(outputProperty, encoded); }
From source file:com.amazonaws.eclipse.core.ui.setupwizard.InitialSetupWizard.java
private static String encodeString(String s) { return new String(Base64.encodeBase64(s.getBytes())); }