org.apache.commons.codec.binary.Base64 # encodeToString ( ) 源码实例Demo

下面列出了 org.apache.commons.codec.binary.Base64 # encodeToString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: archiva   文件: RssFeedServletTest.java

@Test
public void testRequestNewArtifactsInRepo()
    throws Exception
{
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI( "/feeds/test-repo" );
    request.addHeader( "User-Agent", "Apache Archiva unit test" );
    request.setMethod( "GET" );

    Base64 encoder = new Base64( 0, new byte[0] );
    String userPass = "user1:password1";
    String encodedUserPass = encoder.encodeToString( userPass.getBytes() );
    request.addHeader( "Authorization", "BASIC " + encodedUserPass );

    MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();

    rssFeedServlet.doGet( request, mockHttpServletResponse );

    assertEquals( RssFeedServlet.MIME_TYPE, mockHttpServletResponse.getHeader( "CONTENT-TYPE" ) );
    assertNotNull( "Should have recieved a response", mockHttpServletResponse.getContentAsString() );
    assertEquals( "Should have been an OK response code.", HttpServletResponse.SC_OK,
                  mockHttpServletResponse.getStatus() );

}
 
源代码2 项目: beihu-boot   文件: ZipUtils.java

/**
 * 使用zip进行压缩
 *
 * @param str 压缩前的文本
 * @return 返回压缩后的文本
 */
public static String zip(String str) {
    if (str == null)
        return null;
    byte[] compressed;
    String compressedStr = null;
    try (ByteArrayOutputStream out = new ByteArrayOutputStream();
         ZipOutputStream zout = new ZipOutputStream(out)) {
        zout.putNextEntry(new ZipEntry("0"));
        zout.write(str.getBytes());
        zout.closeEntry();
        Base64 base64 = new Base64();
        compressedStr = base64.encodeToString(out.toByteArray());
    } catch (IOException e) {
        compressed = null;
    }
    return compressedStr;
}
 
源代码3 项目: archiva   文件: RssFeedServletTest.java

@Test
public void testRequestNewVersionsOfArtifact()
    throws Exception
{
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI( "/feeds/org/apache/archiva/artifact-two" );
    request.addHeader( "User-Agent", "Apache Archiva unit test" );
    request.setMethod( "GET" );

    //WebRequest request = new GetMethodWebRequest( "http://localhost/feeds/org/apache/archiva/artifact-two" );

    Base64 encoder = new Base64( 0, new byte[0] );
    String userPass = "user1:password1";
    String encodedUserPass = encoder.encodeToString( userPass.getBytes() );
    request.addHeader( "Authorization", "BASIC " + encodedUserPass );

    MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();

    rssFeedServlet.doGet( request, mockHttpServletResponse );

    assertEquals( RssFeedServlet.MIME_TYPE, mockHttpServletResponse.getHeader( "CONTENT-TYPE" ) );
    assertNotNull( "Should have recieved a response", mockHttpServletResponse.getContentAsString() );
    assertEquals( "Should have been an OK response code.", HttpServletResponse.SC_OK,
                  mockHttpServletResponse.getStatus() );
}
 
源代码4 项目: youkefu   文件: UKTools.java

public static String encode(Object obj) {
	Base64 base64 = new Base64();
   	try {
		return base64.encodeToString(UKTools.toBytes(obj)) ;
	} catch (Exception e) {
		e.printStackTrace();
	}
   	return null;
}
 
源代码5 项目: hadoop   文件: Token.java

/**
 * Generate a string with the url-quoted base64 encoded serialized form
 * of the Writable.
 * @param obj the object to serialize
 * @return the encoded string
 * @throws IOException
 */
private static String encodeWritable(Writable obj) throws IOException {
  DataOutputBuffer buf = new DataOutputBuffer();
  obj.write(buf);
  Base64 encoder = new Base64(0, null, true);
  byte[] raw = new byte[buf.getLength()];
  System.arraycopy(buf.getData(), 0, raw, 0, buf.getLength());
  return encoder.encodeToString(raw);
}
 
源代码6 项目: factura-electronica   文件: CFDv33.java

String getSignature(PrivateKey key) throws Exception {
    byte[] bytes = getOriginalBytes();
    Signature sig = Signature.getInstance("SHA256withRSA");
    sig.initSign(key);
    sig.update(bytes);
    byte[] signed = sig.sign();
    Base64 b64 = new Base64(-1);
    return b64.encodeToString(signed);
}
 
源代码7 项目: factura-electronica   文件: CFDv3.java

@Override
public void sellar(PrivateKey key, X509Certificate cert) throws Exception {
    String nc = new String(cert.getSerialNumber().toByteArray());
    if (!nc.equals("20001000000200001428")) {
        cert.checkValidity();
    }
    String signature = getSignature(key);
    document.setSello(signature);
    byte[] bytes = cert.getEncoded();
    Base64 b64 = new Base64(-1);
    String certStr = b64.encodeToString(bytes);
    document.setCertificado(certStr);
    document.setNoCertificado(nc);
}
 

public void sellar(PrivateKey key, X509Certificate cert) throws Exception {
	cert.checkValidity(); 
	String signature = getSignature(key);
	document.setSello(signature);
	byte[] bytes = cert.getEncoded();
	Base64 b64 = new Base64(-1);
	String certStr = b64.encodeToString(bytes);
	document.setCertificado(certStr);
	BigInteger bi = cert.getSerialNumber();
	document.setNoCertificado(new String(bi.toByteArray()));
}
 
源代码9 项目: factura-electronica   文件: CFDv32.java

String getSignature(PrivateKey key) throws Exception {
    byte[] bytes = getOriginalBytes();
    Signature sig = Signature.getInstance("SHA1withRSA");
    sig.initSign(key);
    sig.update(bytes);
    byte[] signed = sig.sign();
    Base64 b64 = new Base64(-1);
    return b64.encodeToString(signed);
}
 
源代码10 项目: factura-electronica   文件: TFDv1.java

String getSignature(PrivateKey key) throws Exception {
    byte[] bytes = getOriginalBytes();
    Signature sig = Signature.getInstance("SHA1withRSA");
    sig.initSign(key);
    sig.update(bytes);
    byte[] signed = sig.sign();
    Base64 b64 = new Base64(-1);
    return b64.encodeToString(signed);
}
 
源代码11 项目: factura-electronica   文件: TFDv11c33.java

String getSignature(PrivateKey key) throws Exception {
    byte[] bytes = getOriginalBytes();
    Signature sig = Signature.getInstance("SHA256withRSA");
    sig.initSign(key);
    sig.update(bytes);
    byte[] signed = sig.sign();
    Base64 b64 = new Base64(-1);
    return b64.encodeToString(signed);
}
 
源代码12 项目: factura-electronica   文件: TFDv1c32.java

String getSignature(PrivateKey key) throws Exception {
    byte[] bytes = getOriginalBytes();
    Signature sig = Signature.getInstance("SHA1withRSA");
    sig.initSign(key);
    sig.update(bytes);
    byte[] signed = sig.sign();
    Base64 b64 = new Base64(-1);
    return b64.encodeToString(signed);
}
 
源代码13 项目: factura-electronica   文件: CFDv22.java

@Override
public void sellar(PrivateKey key, X509Certificate cert) throws Exception {
    String nc = new String(cert.getSerialNumber().toByteArray());
    if (!nc.equals("20001000000200001428")) {
        cert.checkValidity();
    }
    String signature = getSignature(key);
    document.setSello(signature);
    byte[] bytes = cert.getEncoded();
    Base64 b64 = new Base64(-1);
    String certStr = b64.encodeToString(bytes);
    document.setCertificado(certStr);
    document.setNoCertificado(nc);
}
 

String getSignature(PrivateKey key) throws Exception {
	byte[] bytes = getOriginalBytes();
	Signature sig = Signature.getInstance("SHA1withRSA");
	sig.initSign(key);
	sig.update(bytes);
	byte[] signed = sig.sign();
	Base64 b64 = new Base64(-1);
	return b64.encodeToString(signed);
}
 

public void sellar(PrivateKey key, X509Certificate cert) throws Exception {
	cert.checkValidity(); 
	String signature = getSignature(key);
	document.setSello(signature);
	byte[] bytes = cert.getEncoded();
	Base64 b64 = new Base64(-1);
	String certStr = b64.encodeToString(bytes);
	document.setCertificado(certStr);
	BigInteger bi = cert.getSerialNumber();
	document.setNoCertificado(new String(bi.toByteArray()));
}
 

public void sellar(PrivateKey key, X509Certificate cert) throws Exception {
	cert.checkValidity(); 
	String signature = getSignature(key);
	document.setSello(signature);
	byte[] bytes = cert.getEncoded();
	Base64 b64 = new Base64(-1);
	String certStr = b64.encodeToString(bytes);
	document.setCertificado(certStr);
	BigInteger bi = cert.getSerialNumber();
	document.setNoCertificado(new String(bi.toByteArray()));
}
 

String getSignature(PrivateKey key) throws Exception {
	byte[] bytes = getOriginalBytes();
	Signature sig = Signature.getInstance("SHA1withRSA");
	sig.initSign(key);
	sig.update(bytes);
	byte[] signed = sig.sign();
	Base64 b64 = new Base64(-1);
	return b64.encodeToString(signed);
}
 
源代码18 项目: beihu-boot   文件: ZipUtils.java

public static String base64Encode(byte[] input)
{

    Base64 base64 = new Base64();
    return base64.encodeToString(input);
}
 
源代码19 项目: TensorFlowOnYARN   文件: ClusterSpec.java

private String base64Encoded(String json) throws JsonProcessingException {
  byte[] data = json.getBytes();
  Base64 encoder = new Base64(0, null, true);
  return encoder.encodeToString(data);
}
 

private static String exportCert(X509Certificate cert) throws Exception {

    Base64 encoder = new Base64(64);

    String b64 = encoder.encodeToString(cert.getEncoded());

    b64 = "-----BEGIN CERTIFICATE-----\n" + b64 + "-----END CERTIFICATE-----\n";

    return b64;
  }