Example usage for org.apache.commons.codec.binary Base64 Base64

List of usage examples for org.apache.commons.codec.binary Base64 Base64

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary Base64 Base64.

Prototype

public Base64(final int lineLength) 

Source Link

Document

Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.

Usage

From source file:com.leclercb.commons.api.license.LicenseManager.java

public static InputStream keyDecoder(String publicKey) throws Exception {
    Base64 base64 = new Base64(40);
    byte[] data = base64.decode(publicKey);

    return new ByteArrayInputStream(data);
}

From source file:com.vmware.o11n.plugin.crypto.model.CryptoUtil.java

/**
 * PEM encode a public key//ww w. j a v a2s .  c  o m
 *
 * @param pubKey Public
 * @return PEM encoded public key string
 */
public static String pemEncode(PublicKey pubKey) {
    String toReturn;
    if (pubKey instanceof RSAPublicKey) {
        final String keyHeader = FIVE_DASH + "BEGIN PUBLIC KEY" + FIVE_DASH;
        final String keyFooter = FIVE_DASH + "END PUBLIC KEY" + FIVE_DASH;
        Base64 encoder = new Base64(64);
        toReturn = String.join("\n", keyHeader, new String(encoder.encode(pubKey.getEncoded())), keyFooter);
    } else {
        throw new UnsupportedOperationException("Unknown public key type.  Only implemented for RSAPublicKey.");
    }
    return CryptoUtil.fixPemString(toReturn);
}

From source file:ch.boye.httpclientandroidlib.impl.auth.BasicScheme.java

/**
 * Creates an instance of <tt>BasicScheme</tt> with the given challenge state.
 *
 * @since 4.2/*from ww  w  .ja v  a 2 s. c o  m*/
 * @deprecated (4.3) do not use.
 */
@Deprecated
public BasicScheme(final ChallengeState challengeState) {
    super(challengeState);
    this.base64codec = new Base64(0);
}

From source file:com.buddycloud.mediaserver.delete.DeleteMediaTest.java

@Test
public void deleteMediaParamAuth() throws Exception {
    Base64 encoder = new Base64(true);
    String authStr = BASE_USER + ":" + BASE_TOKEN;

    ClientResource client = new ClientResource(URL + "?auth=" + new String(encoder.encode(authStr.getBytes())));

    client.delete();//from   w  ww  .  j ava 2  s  .c  om

    Assert.assertFalse(fileToDelete.exists());
}

From source file:com.buddycloud.mediaserver.delete.DeleteAvatarTest.java

@Test
public void deleteAvatarParamAuth() throws Exception {
    Base64 encoder = new Base64(true);
    String authStr = BASE_USER + ":" + BASE_TOKEN;

    ClientResource client = new ClientResource(URL + "?auth=" + new String(encoder.encode(authStr.getBytes())));

    client.delete();/*  w ww  .  j  a v a2s .c  om*/

    Assert.assertFalse(fileToDelete.exists());
}

From source file:com.lucidworks.security.authentication.util.Signer.java

/**
 * Returns then signature of a string.// w  w w.j  av a2s  . c  o  m
 *
 * @param str string to sign.
 *
 * @return the signature for the string.
 */
protected String computeSignature(String str) {
    try {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(str.getBytes());
        md.update(secret);
        byte[] digest = md.digest();
        return new Base64(0).encodeToString(digest);
    } catch (NoSuchAlgorithmException ex) {
        throw new RuntimeException("It should not happen, " + ex.getMessage(), ex);
    }
}

From source file:freeipa.client.negotiation.JBossNegotiateScheme.java

/**
 * Default constructor for the Negotiate authentication scheme.
 *///  w  ww  .ja  v a  2s.  c  o m
public JBossNegotiateScheme(boolean stripPort) {
    super();
    this.state = State.UNINITIATED;
    this.stripPort = stripPort;
    this.base64codec = new Base64(0);
}

From source file:com.cloudera.alfredo.util.Signer.java

/**
 * Returns then signature of a string.// w  w w . j  a va  2  s. c o m
 *
 * @param str string to sign.
 * @return the signature for the string.
 */
protected String computeSignature(String str) {
    try {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(str.getBytes());
        md.update(secret);
        byte[] digest = md.digest();
        Base64 base64 = new Base64(0);
        return base64.encodeToString(digest);
    } catch (NoSuchAlgorithmException ex) {
        throw new RuntimeException("It should not happen, " + ex.getMessage(), ex);
    }
}

From source file:mx.bigdata.cfdi.CFDv3.java

public void sign(PrivateKey key, Certificate cert) throws Exception {
    String signature = getSignature(key);
    document.setSello(signature);/*from w  w  w. j  av a 2  s. co m*/
    byte[] bytes = cert.getEncoded();
    Base64 b64 = new Base64(-1);
    String certStr = b64.encodeToString(bytes);
    document.setCertificado(certStr);
}

From source file:de.zib.scalaris.examples.wikipedia.data.Revision.java

/**
 * Gets the compressed revision text.//from w  ww  . j av  a2 s  . c  o  m
 * 
 * @return the text
 */
public String getB64pText() {
    Base64 b64 = new Base64(0);
    return b64.encodeToString(pText);
}