当前位置: 首页>>代码示例>>Java>>正文


Java Base64.encodeBase64方法代码示例

本文整理汇总了Java中org.apache.commons.codec.binary.Base64.encodeBase64方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.encodeBase64方法的具体用法?Java Base64.encodeBase64怎么用?Java Base64.encodeBase64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.codec.binary.Base64的用法示例。


在下文中一共展示了Base64.encodeBase64方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkConnection

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
/**
 * @description 判断服务连通性
 * @author yi.zhang
 * @time 2017年4月19日 下午6:00:40
 * @param url
 * @param auth	认证信息(username+":"+password)
 * @return (true:连接成功,false:连接失败)
 */
public static boolean checkConnection(String url,String auth){
	boolean flag = false;
	try {
		HttpURLConnection connection = (HttpURLConnection)new URL(url).openConnection();
		connection.setConnectTimeout(5*1000);
		if(auth!=null&&!"".equals(auth)){
			String authorization = "Basic "+new String(Base64.encodeBase64(auth.getBytes()));
			connection.setRequestProperty("Authorization", authorization);
		}
		connection.connect();
		if(connection.getResponseCode()==HttpURLConnection.HTTP_OK){
			flag = true;
		}
		connection.disconnect();
	}catch (Exception e) {
		logger.error("--Server Connect Error !",e);
	}
	return flag;
}
 
开发者ID:dev-share,项目名称:database-transform-tool,代码行数:28,代码来源:HttpUtil.java

示例2: encrypt

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
/**
 * Encrypt the message with the given key.
 * 
 * @param message
 *            Ciphered message.
 * @param secretKey
 *            The secret key.
 * @return the original message.
 */
protected String encrypt(final String message, final String secretKey) throws Exception { // NOSONAR
	// SSO digest algorithm used for password. This
	final MessageDigest md = MessageDigest.getInstance(getDigest());
	final byte[] digestOfPassword = md.digest(secretKey.getBytes(StandardCharsets.UTF_8));
	final byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);

	// Cipher implementation.
	final String algo = get("sso.crypt", DEFAULT_IMPL);

	final SecretKey key = new SecretKeySpec(keyBytes, algo);
	final Cipher cipher = Cipher.getInstance(algo);
	cipher.init(Cipher.ENCRYPT_MODE, key);
	final byte[] plainTextBytes = message.getBytes(StandardCharsets.UTF_8);
	final byte[] buf = cipher.doFinal(plainTextBytes);
	final byte[] base64Bytes = Base64.encodeBase64(buf);
	return new String(base64Bytes, StandardCharsets.UTF_8);
}
 
开发者ID:ligoj,项目名称:plugin-sso-salt,代码行数:27,代码来源:SaltedAuthenticationResource.java

示例3: setStartArguments

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
/**
 * This method can be used in order to save the start arguments of the current agent.
 * Internally these arguments will be kept as Base64 encoded Strings in order to 
 * store this configuration also in the SimulationSetup
 *  
 * @param startArguments the startInstances to set for the agent start up
 * @see agentgui.core.project.setup.SimulationSetup
 */
public void setStartArguments(String[] startArguments) {
	
	if (startArguments.length==0) {
		this.startArguments = null;
		return;
	}
	String[] startArgumentsEncoded = new String[startArguments.length];
	String encodedArgument = null;
	try {
		for (int i = 0; i < startArguments.length; i++) {
			encodedArgument = new String(Base64.encodeBase64(startArguments[i].getBytes("UTF8")));
			startArgumentsEncoded[i] = encodedArgument;
		}
		
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
	this.startArguments = startArgumentsEncoded;
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:28,代码来源:AgentClassElement4SimStart.java

示例4: encrypt

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
public static String encrypt(String str) {
    if (str == null) return null;
    Cipher cipher;
    try {
        cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, keySpec,
                new IvParameterSpec(ips.getBytes("UTF-8")));

        byte[] encrypted = cipher.doFinal(str.getBytes("UTF-8"));
        String Str = new String(Base64.encodeBase64(encrypted));
        return Str;
    } catch (NoSuchAlgorithmException | NoSuchPaddingException
            | InvalidKeyException | InvalidAlgorithmParameterException
            | IllegalBlockSizeException | BadPaddingException
            | UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:JoMingyu,项目名称:Server-Quickstart-Vert.x,代码行数:20,代码来源:AES256.java

示例5: encryptAES_ECB_PKCS5Padding

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
/**
 * Encrypt DATA
 * @param value
 * @return
 */
public static String encryptAES_ECB_PKCS5Padding(String value) {
    try {
        byte[] key = {
                1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1
        };
        SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");

        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec);

        byte[] encrypted = cipher.doFinal(value.getBytes());

        Base64 b64 = new Base64();
        System.out.println("encrypted string: " + new String(b64.encodeBase64(encrypted)));

        return new String(b64.encodeBase64(encrypted));
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return "";
}
 
开发者ID:HTBridge,项目名称:pivaa,代码行数:28,代码来源:Encryption.java

示例6: testHash

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
@Test
public void testHash() throws Exception
{
    NumericPathHasher nph = new NumericPathHasher();

    Pair<String, String> h1 = nph.hash("/1/2/3");
    assertEquals(new Pair<String, String>("123",
                                          null),
                 h1);

    Pair<String, String> h2 = nph.hash("/a/2/3");
    String xc2 = new String(Base64.encodeBase64("/a/2/3".getBytes(),
                                                false));
    assertEquals(new Pair<String, String>(null,
                                          xc2),
                 h2);

    Pair<String, String> h3 = nph.hash("/1/2/a/1/3");
    String xc3 = new String(Base64.encodeBase64("a/1/3".getBytes(),
                                                false));
    assertEquals(new Pair<String, String>("12",
                                          xc3),
                 h3);

}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:26,代码来源:NumericPathHasherTest.java

示例7: computeAccessSignature

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
private String computeAccessSignature(String timestamp, HttpMethod method, String urlTxt, ByteBuffer body)
        throws GeneralSecurityException {
    if (conn == null) {
        throw new IllegalStateException("cannot generate exchange request post-disconnect()");
    }

    String prehash = timestamp + method.name() + urlTxt;

    Mac mac = Mac.getInstance("HmacSHA256");
    mac.init(signingKey);
    mac.update(prehash.getBytes());
    if (body != null) {
        mac.update(body);
    }
    return new String(Base64.encodeBase64(mac.doFinal()));
}
 
开发者ID:cloudwall,项目名称:libcwfincore,代码行数:17,代码来源:GdaxExchangeSession.java

示例8: AESEncrypt

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
/**
 * @Description: AES 加密
 * @param  keyStr 密钥
 * @param  plainText 加密数据
 * @return String 加密完数据
 * @throws
 * @author liuxm
 * @date 2014年11月21日
 */
public static String AESEncrypt(String keyStr, String plainText) throws Exception {
    byte[] encrypt = null;
    try {
        Key key = generateKey(keyStr);
        Cipher cipher = Cipher.getInstance(AES_TYPE);
        cipher.init(Cipher.ENCRYPT_MODE, key);
        encrypt = cipher.doFinal(plainText.getBytes());
        return new String(Base64.encodeBase64(encrypt));
    } catch (Exception e) {
        LOGGER.error("aes encrypt failure : {}", e);
        throw e;
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:23,代码来源:EncryptionUtil.java

示例9: getBase64Authentication

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
public String getBase64Authentication(String url, String user, String password) {
	String base64Creds = null;
	if (user != null) {
		String plainCreds = user + ":" + (password == null ? "" : password);
		byte[] plainCredsBytes = plainCreds.getBytes();
		byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
		base64Creds = new String(base64CredsBytes);			
	}
	return base64Creds;
}
 
开发者ID:graphium-project,项目名称:graphium,代码行数:11,代码来源:GraphVersionImportFinishedHttpNotifierImpl.java

示例10: AESEncrypt

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
/**
 * @param keyStr
 *         密钥
 * @param plainText
 *         加密数据
 *
 * @return String 加密完数据
 *
 * @throws
 * @Description: AES 加密
 */
public static String AESEncrypt(final String keyStr, final String plainText) throws Exception {
    byte[] encrypt;
    try {
        Key key = generateKey(keyStr);
        Cipher cipher = Cipher.getInstance(AES_TYPE);
        cipher.init(Cipher.ENCRYPT_MODE, key);
        encrypt = cipher.doFinal(plainText.getBytes());
        return new String(Base64.encodeBase64(encrypt));
    } catch (Exception e) {
        LOGGER.error("aes encrypt failure : {}", e);
        throw e;
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:25,代码来源:AESEncrypt.java

示例11: viewableDeregister

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
public Result viewableDeregister(
		String viewableURN
	) 
	    throws IOException, 
	           URISyntaxException
	{
		String scope[] = { SCOPE_DATA_READ, SCOPE_DATA_WRITE };
		ResultAuthentication authResult = authenticate( scope );
		if( authResult.isError() )
		{
			return authResult;
		}

		viewableURN = new String( Base64.encodeBase64( viewableURN.getBytes() ) );
		String params[] = { viewableURN };
		String frag = makeURN( API_VIEWING, PATT_VIEW_DEREGISTER, params );
		
		URI uri = new URI( _protocol, null, lookupHostname(), _port, frag, null, null );

		URL url = new URL( uri.toASCIIString() );
		HttpURLConnection connection = (HttpURLConnection)url.openConnection();

		connection.setRequestMethod( "DELETE" );
		authResult.setAuthHeader( connection );
//        connection.setRequestProperty( "Accept", "Application/json" );
		
		return new Result( connection );
	}
 
开发者ID:IBM,项目名称:MaximoForgeViewerPlugin,代码行数:29,代码来源:DataRESTAPI.java

示例12: sendMessage

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
public boolean sendMessage(String type, String target, String message)
{
	String context;
	context = type + " " + target + " ";
	try
	{
		context += Base64.encodeBase64(message.getBytes("GB18030"));
	} catch (UnsupportedEncodingException e)
	{
		System.out.println("错误:当前Java虚拟机不支持GB18030编码");
		e.printStackTrace();
	}
	sendMessages.offer(context);
	return true;
}
 
开发者ID:XiLingHost,项目名称:tg-qq-trans,代码行数:16,代码来源:QQRunner.java

示例13: encodeBase64

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
/**
 * Base64编码.
 */
public static String encodeBase64(String input) {
	try {
		return new String(Base64.encodeBase64(input.getBytes(DEFAULT_URL_ENCODING)));
	} catch (UnsupportedEncodingException e) {
		return "";
	}
}
 
开发者ID:egojit8,项目名称:easyweb,代码行数:11,代码来源:Encodes.java

示例14: viewableQueryMetadata

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
/**
 * Returns a list of model view (metadata) IDs for a design model. The metadata ID enables end
 * users to select an object tree and properties for a specific model view. 
 *  
 * <p>Although most design apps (e.g., Fusion and Inventor) only allow a single model view 
 * (object tree and set of properties), some apps (e.g., Revit) allow users to design models 
 * with multiple model views (e.g., HVAC, architecture, perspective). 
 *  
 * <p>Note that you can only retrieve metadata from  an input file that has been translated into 
 * an SVF file.
 *  
 * @param viewableURN The Base64 (URL Safe) encoded design URN
 */
public ResultViewableMetadata viewableQueryMetadata(
	String viewableURN
) 
    throws IOException, 
           URISyntaxException
{
	String scope[] = { SCOPE_DATA_READ };
	ResultAuthentication authResult = authenticate( scope );
	if( authResult.isError() )
	{
		return new ResultViewableMetadata( authResult );
	}
	
	viewableURN = new String( Base64.encodeBase64( viewableURN.getBytes() ) );

	String params[] = { viewableURN };
	String frag = makeURN( API_VIEWING, PATT_VIEW_METADATA, params );

	URI uri = new URI( _protocol, null, lookupHostname(), _port, frag, null, null );

	URL url = new URL( uri.toASCIIString() );
	HttpURLConnection connection = (HttpURLConnection)url.openConnection();

	connection.setRequestMethod( "GET" );
	authResult.setAuthHeader( connection );
       connection.setRequestProperty( "Accept", "Application/json" );

	return new ResultViewableMetadata( connection );
}
 
开发者ID:IBM,项目名称:MaximoForgeViewerPlugin,代码行数:43,代码来源:DataRESTAPI.java

示例15: encodeIdentifier

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
static String encodeIdentifier(byte[] identifier) {
  return new String(Base64.encodeBase64(identifier));
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:4,代码来源:SaslUtil.java


注:本文中的org.apache.commons.codec.binary.Base64.encodeBase64方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。