Java Code Examples for com.jeesuite.common.crypt.Base64#encodeToString()

The following examples show how to use com.jeesuite.common.crypt.Base64#encodeToString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RsaSignUtils.java    From jeesuite-libs with Apache License 2.0 6 votes vote down vote up
/** 
 * 随机生成密钥对 
 */  
public static String[] generateKeyPair() {  
    // KeyPairGenerator类用于生成公钥和私钥对,基于RSA算法生成对象  
    KeyPairGenerator keyPairGen = null;  
    try {  
        keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM);  
    } catch (NoSuchAlgorithmException e) {  
        // TODO Auto-generated catch block  
        e.printStackTrace();  
    }  
    // 初始化密钥对生成器,密钥大小为96-1024位  
    keyPairGen.initialize(KEY_SIZE,new SecureRandom());  
    // 生成一个密钥对,保存在keyPair中  
    KeyPair keyPair = keyPairGen.generateKeyPair();  
    RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();  
    RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();  
    String publicKeyString = Base64.encodeToString(publicKey.getEncoded(),true);  
    String privateKeyString = Base64.encodeToString(privateKey.getEncoded(),true); 
    
    return new String[]{publicKeyString,privateKeyString};
}
 
Example 2
Source File: CryptComponent.java    From jeesuite-config with Apache License 2.0 5 votes vote down vote up
private static String encryptWithAES(String key, String data){
	try {
		String secretKey = DigestUtils.md5(key).substring(16);
		byte[] bytes = AES.encrypt(data.getBytes(StandardCharsets.UTF_8), secretKey.getBytes(StandardCharsets.UTF_8));
		return  Base64.encodeToString(bytes, false);
	} catch (Exception e) {
		throw new JeesuiteBaseException(9999, "加密失败");
	}
}
 
Example 3
Source File: DigestUtils.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
public static String encodeBase64(String string){
	try {
		return Base64.encodeToString(string.getBytes(CARTSET_UTF_8), false);
	} catch (UnsupportedEncodingException e) {
		throw new RuntimeException(e);
	}
}
 
Example 4
Source File: HttpRequestEntity.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
public String getEncodeBasicAuth(){
	String encoded = Base64.encodeToString((name + ":" + password).getBytes(StandardCharsets.UTF_8),false);
	return "Basic "+encoded;
}
 
Example 5
Source File: RsaSignUtils.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
public static String encrypt(PublicKey key, String plainText) {
	byte[] encodeBytes = encrypt(key, plainText.getBytes(StandardCharsets.UTF_8));
	return Base64.encodeToString(encodeBytes, false);
}