List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64URLSafe
public static byte[] encodeBase64URLSafe(final byte[] binaryData)
From source file:com.cliqset.magicsig.util.KeyGen.java
public static void main(String[] args) { try {//from w w w . j ava2 s. c o m FileOutputStream fos = new FileOutputStream(fileName); for (int x = 0; x < numKeys; x++) { fos.write((x + " RSA.").getBytes("ASCII")); KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(keySize); KeyPair keyPair = keyPairGenerator.genKeyPair(); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); RSAPublicKeySpec publicSpec = keyFactory.getKeySpec(keyPair.getPublic(), RSAPublicKeySpec.class); RSAPrivateKeySpec privateSpec = keyFactory.getKeySpec(keyPair.getPrivate(), RSAPrivateKeySpec.class); fos.write(Base64.encodeBase64URLSafe(getBytes(publicSpec.getModulus()))); fos.write(".".getBytes("ASCII")); fos.write(Base64.encodeBase64URLSafe(getBytes(publicSpec.getPublicExponent()))); fos.write(".".getBytes("ASCII")); fos.write(Base64.encodeBase64URLSafe(getBytes(privateSpec.getPrivateExponent()))); fos.write("\n".getBytes("ASCII")); System.out.println(x); } fos.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.esofthead.mycollab.common.UrlEncodeDecoder.java
/** * /* w ww . ja v a 2s. c om*/ * @param str * @return */ public static String encode(String str) { try { if (StringUtils.isBlank(str)) { return ""; } return URLEncoder.encode(new String(Base64.encodeBase64URLSafe(str.getBytes("UTF-8")), "UTF-8"), "UTF-8"); } catch (UnsupportedEncodingException ex) { throw new MyCollabException(ex); } }
From source file:eu.dety.burp.joseph.utilities.Decoder.java
/** * Safe URL encode a byte array to a String * //from w ww. j ava 2 s .c o m * @param input * byte array input * @return base64url encoded string */ public static String base64UrlEncode(byte[] input) { return new String(Base64.encodeBase64URLSafe(input)); }
From source file:core.SHA256Hash.java
public static String CalculateCheckSumBase64(String FileName, String url) throws Exception { MessageDigest md = MessageDigest.getInstance(SHA256); FileInputStream fileHandle = new FileInputStream(FileName); byte[] dataBytes = new byte[1024]; int nread = 0; while ((nread = fileHandle.read(dataBytes)) != -1) { md.update(dataBytes, 0, nread);/*from w w w.j a va2 s . c om*/ } ; byte[] mdbytes = md.digest(); byte[] bytes = null; if (SHA256 == getHashAlgType(url)) { // Do base64 encoding bytes = Base64.encodeBase64URLSafe(mdbytes); } else { if (SHA256_16 == getHashAlgType(url)) bytes = Base64.encodeBase64(new byte[] { mdbytes[0], mdbytes[1] }, false, true, 4); } // Store byte array as string and return it String value = new String(bytes); System.out.println("Base64 encoded " + getHashAlgType(url) + " hash: " + value); return value; }
From source file:javafx1.Testpics.java
private void bildSchleife() { File f = new File("F:/NetBeansProjekte/pictures"); File[] fileArray = f.listFiles(); java.util.Arrays.sort(fileArray); for (File file : fileArray) { try {/*from w w w . j a va 2 s . c o m*/ System.out.println("file: " + file.getCanonicalPath()); File outputfile = new File(file.getCanonicalPath() + ".jpg"); BufferedImage bi = ImageIO.read(file); System.out.println(" enc" + encodeToString(bi, "jpg")); ImageIO.write(bi, "jpg", outputfile); bi = ImageIO.read(outputfile); System.out.println(" w" + bi.getWidth() + " h" + bi.getHeight()); byte[] data = ((DataBufferByte) bi.getRaster().getDataBuffer()).getData(); // System.out.println(new String(data)); byte[] x = Base64.encodeBase64URLSafe(data); System.out.println("x" + new String(x)); String b64 = Base64.encodeBase64String(data); System.out.println("64" + b64); // byte[] backToBytes = Base64.decodeBase64(base64String); // InputStream in = new ByteArrayInputStream(backToBytes); // BufferedImage bi; // bi = ImageIO.read(in); //byte[] xx = base64String.getBytes(StandardCharsets.UTF_8); // bild, wie es von http kommt // RunPic rp = new RunPic(this, data); // Platform.runLater(rp); try { Thread.sleep(50); break; } catch (InterruptedException ex) { Logger.getLogger(JavaFX1.class.getName()).log(Level.SEVERE, null, ex); } } catch (IOException ex) { Logger.getLogger(JavaFX1.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.kolich.common.util.crypt.Base64Utils.java
/** * Encodes binary data using a URL-safe variation of the base64 * algorithm but does not chunk the output. The url-safe variation * emits - and _ instead of + and / characters. * @param encode//w ww . j av a 2 s . c o m * @return */ public static final byte[] encodeBase64URLSafe(final byte[] encode) { return Base64.encodeBase64URLSafe(encode); }
From source file:net.nicholaswilliams.java.licensing.encryption.Encryptor.java
/** * Encrypt the binary data using the default passphrase. * For encrypting, the data will first be padded to a safe number of * bytes with randomized data.//w ww . j a v a 2s. c o m * * @param unencrypted The binary data to encrypt * @return the encrypted string Base64-encoded. * @see Encryptor#pad(byte[], int) */ public static String encrypt(byte[] unencrypted) { return new String(Base64.encodeBase64URLSafe(Encryptor.encryptRaw(unencrypted)), LicensingCharsets.UTF_8); }
From source file:com.cloudant.client.internal.views.PaginationToken.java
/** * Generate an opaque pagination token from the supplied PageMetadata. * * @param pageMetadata page metadata of the page for which the token should be generated * @return opaque pagination token//from w w w . j a va2 s . c o m */ static String tokenize(PageMetadata<?, ?> pageMetadata) { try { Gson g = getGsonWithKeyAdapter(pageMetadata.pageRequestParameters); return new String( Base64.encodeBase64URLSafe(g.toJson(new PaginationToken(pageMetadata)).getBytes("UTF-8")), Charset.forName("UTF-8")); } catch (UnsupportedEncodingException e) { //all JVMs should support UTF-8 throw new RuntimeException(e); } }
From source file:net.nicholaswilliams.java.licensing.encryption.Encryptor.java
/** * Encrypt the binary data. For encrypting, the * data will first be padded to a safe number of * bytes with randomized data.//ww w .j a v a2 s .com * * @param unencrypted The binary data to encrypt * @param passphrase The passphrase to encrypt the data with * @return the encrypted string Base64-encoded. * @see Encryptor#pad(byte[], int) */ public static String encrypt(byte[] unencrypted, char[] passphrase) { return new String(Base64.encodeBase64URLSafe(Encryptor.encryptRaw(unencrypted, passphrase)), LicensingCharsets.UTF_8); }
From source file:edu.utdallas.bigsecret.crypter.CrypterMode2.java
/** * {@inheritDoc}//from ww w . j a va 2 s .c om */ public byte[] getIndexFamilyData(byte[] family) throws Exception { return Base64.encodeBase64URLSafe(getFamilyHash(family)); }