當前位置: 首頁>>代碼示例>>Java>>正文


Java Encoder.encodeToString方法代碼示例

本文整理匯總了Java中java.util.Base64.Encoder.encodeToString方法的典型用法代碼示例。如果您正苦於以下問題:Java Encoder.encodeToString方法的具體用法?Java Encoder.encodeToString怎麽用?Java Encoder.encodeToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Base64.Encoder的用法示例。


在下文中一共展示了Encoder.encodeToString方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: rfc4648Base64Encode

import java.util.Base64.Encoder; //導入方法依賴的package包/類
static String rfc4648Base64Encode(String arg) throws UnsupportedEncodingException {
	Encoder encoder = Base64.getMimeEncoder(0, new byte[0]);
	String res = encoder.encodeToString(arg.getBytes(TEXT_ENCODING));
	res = res.replace("/", "_");
	res = res.replace("+", "-");
	res = res.replace("=", "");
	return res;
}
 
開發者ID:normalian,項目名稱:PowerBI-Embedded-Sample-Java,代碼行數:9,代碼來源:PowerBIHelper.java

示例2: aesEncryptString

import java.util.Base64.Encoder; //導入方法依賴的package包/類
public static String aesEncryptString(String content, String key) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException {
    byte[] contentBytes = content.getBytes(charset);
    byte[] keyBytes = key.getBytes(charset);
    byte[] encryptedBytes = aesEncryptBytes(contentBytes, keyBytes);
    Encoder encoder = Base64.getEncoder();
    return encoder.encodeToString(encryptedBytes);
}
 
開發者ID:whoszus,項目名稱:HeatSeeking,代碼行數:8,代碼來源:AES.java

示例3: createContent

import java.util.Base64.Encoder; //導入方法依賴的package包/類
public static Content createContent(IExtensionHelpers helpers, byte[] httpResponse) {
    String[] response = new String(httpResponse).split("\r\n\r\n");

    // size
    int size = 0;
    if (response.length > 1) {
        size = response[1].getBytes().length;
    }
    
    // mimeType
    String mimeType = getMimeType(httpResponse);

    
    String base64String = "";
    if (response.length > 1) {
        IResponseInfo iResInfo =  helpers.analyzeResponse(httpResponse);
        int bodyPos = iResInfo.getBodyOffset();
        byte[] bodybyte = Arrays.copyOfRange(httpResponse,bodyPos,httpResponse.length);
        
        Encoder encoder = Base64.getMimeEncoder();
        encoder = Base64.getMimeEncoder();
        base64String = encoder.encodeToString(bodybyte);
    }

    Content retContent = new Content.Builder().size(size).compression(0).encoding("base64").mimeType(mimeType)
            .text(base64String).build();

    return retContent;
}
 
開發者ID:OgaworldEX,項目名稱:BurpExtender_OgaHarSave,代碼行數:30,代碼來源:HttpRequestResponse.java

示例4: aesEncryptString

import java.util.Base64.Encoder; //導入方法依賴的package包/類
public static String aesEncryptString(String content, String key) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException {
	byte[] contentBytes = content.getBytes(charset);
	byte[] keyBytes = key.getBytes(charset);
	byte[] encryptedBytes = aesEncryptBytes(contentBytes, keyBytes);
	Encoder encoder = Base64.getEncoder();
    return encoder.encodeToString(encryptedBytes);
}
 
開發者ID:WelkinXie,項目名稱:AESCipher-Java,代碼行數:8,代碼來源:AESCipher.java

示例5: generateApiKey

import java.util.Base64.Encoder; //導入方法依賴的package包/類
public static String generateApiKey(){
    Encoder e = Base64.getEncoder();
    ByteBuffer bb = ByteBuffer.wrap(new byte[16*2]);
    for(int i=0;i<2; i++){
        UUID u = UUID.randomUUID();
        bb.putLong(u.getMostSignificantBits());
        bb.putLong(u.getLeastSignificantBits());
    }
    return e.encodeToString(bb.array());
}
 
開發者ID:gameontext,項目名稱:gameon-player,代碼行數:11,代碼來源:SharedSecretGenerator.java

示例6: encryptIntegers

import java.util.Base64.Encoder; //導入方法依賴的package包/類
/**
 * Encrypt an array of integers to a String.
 * 
 * @param integers
 * @param context
 * @return
 * @throws ServletException
 */
public static String encryptIntegers(int integers[], String password) throws ServletException {
	/* Generate salt. */
	SecureRandom rand = new SecureRandom();
	byte salt[] = new byte[8];
	rand.nextBytes(salt);

	byte[] iv;
	byte[] ciphertext;
	try {
		/* Derive the key, given password and salt. */
		SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
		KeySpec spec = new PBEKeySpec(password.toCharArray(), salt, 65536, 256);
		SecretKey tmp = factory.generateSecret(spec);
		SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES");

		/* Encrypt the SampleSetID. */
		Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
		cipher.init(Cipher.ENCRYPT_MODE, secret);
		AlgorithmParameters params = cipher.getParameters();
		iv = params.getParameterSpec(IvParameterSpec.class).getIV();

		ByteBuffer buff = ByteBuffer.allocate(integers.length * 4);
		for (int i = 0; i < integers.length; ++i) {
			buff.putInt(integers[i]);
		}
		ciphertext = cipher.doFinal(buff.array());
	} catch (Exception ex) {
		throw new ServletException(ex);
	}

	/* Store the encrypted SampleSetID in a cookie */

	Encoder encoder = Base64.getEncoder();
	String encryptedStr = encoder.encodeToString(ciphertext) + "|" + encoder.encodeToString(iv) + "|" + encoder.encodeToString(salt);
	return encryptedStr;
}
 
開發者ID:qqTYXn7,項目名稱:browserprint,代碼行數:45,代碼來源:Encryption.java

示例7: encryptInteger

import java.util.Base64.Encoder; //導入方法依賴的package包/類
/**
 * Encrypt an integer to a String.
 * 
 * @param integer
 * @param context
 * @return
 * @throws ServletException
 */
private static String encryptInteger(Integer integer, ServletContext context) throws ServletException {
	/* Get password. */
	String password = context.getInitParameter("SampleSetIDEncryptionPassword");

	/* Generate salt. */
	SecureRandom rand = new SecureRandom();
	byte salt[] = new byte[8];
	rand.nextBytes(salt);

	byte[] iv;
	byte[] ciphertext;
	try {
		/* Derive the key, given password and salt. */
		SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
		KeySpec spec = new PBEKeySpec(password.toCharArray(), salt, 65536, 256);
		SecretKey tmp = factory.generateSecret(spec);
		SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES");

		/* Encrypt the SampleSetID. */
		Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
		cipher.init(Cipher.ENCRYPT_MODE, secret);
		AlgorithmParameters params = cipher.getParameters();
		iv = params.getParameterSpec(IvParameterSpec.class).getIV();
		ciphertext = cipher.doFinal(ByteBuffer.allocate(4).putInt(integer).array());
	} catch (Exception ex) {
		throw new ServletException(ex);
	}

	/* Store the encrypted SampleSetID in a cookie */

	Encoder encoder = Base64.getEncoder();
	String encryptedStr = encoder.encodeToString(ciphertext) + "|" + encoder.encodeToString(iv) + "|" + encoder.encodeToString(salt);
	return encryptedStr;
}
 
開發者ID:qqTYXn7,項目名稱:browserprint,代碼行數:43,代碼來源:SampleIDs.java

示例8: encode

import java.util.Base64.Encoder; //導入方法依賴的package包/類
/**
 * Returns an encoded BASE64 string of the value.
 * 
 * @param salt
 *        the salt to use for encoding
 * @param value
 *        value to encode
 * 
 * @return encoded BASE64 string of the value or null if no value given
 * 
 * @throws CipherException
 */
public static String encode(String salt, String value)
        throws CipherException
{
    // verify value
    if (null == value || value.isEmpty())
    {
        return null;
    }

    // create cipher object
    SecretKeySpec keySpec = createAESCipher(salt);

    Cipher cipher;
    try
    {
        cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.ENCRYPT_MODE, keySpec);
        byte[] enc = cipher.doFinal(value.getBytes());

        Encoder encoder = Base64.getEncoder();
        return encoder.encodeToString(enc);
    }
    catch (Exception e)
    {
        throw new CipherException("Error during encryption.", e);
    }
}
 
開發者ID:AlfrescoBenchmark,項目名稱:alfresco-benchmark,代碼行數:40,代碼來源:AESCipher.java

示例9: encodePropertyValue

import java.util.Base64.Encoder; //導入方法依賴的package包/類
private String encodePropertyValue(final String value) throws IllegalArgumentException, EncryptionException {
    // simply obfuscate the values from clear text.
    final Encoder encoder = Base64.getUrlEncoder();
    final String encoded = encoder.encodeToString(value.getBytes());
    return encoded;
}
 
開發者ID:blackducksoftware,項目名稱:hub-email-extension,代碼行數:7,代碼來源:OAuthConfigManager.java

示例10: toBase64

import java.util.Base64.Encoder; //導入方法依賴的package包/類
public static String toBase64(byte[] bytes){
	Encoder b64 = Base64.getEncoder();
	
	return b64.encodeToString(bytes);
}
 
開發者ID:tylerhasman,項目名稱:MapleStory,代碼行數:6,代碼來源:AccountEncryption.java

示例11: of

import java.util.Base64.Encoder; //導入方法依賴的package包/類
static Crypted of(String info, byte[] content, byte[] iv) {
  Encoder encoder = getEncoder();
  String contentBase64 = encoder.encodeToString(content);
  String ivBase64 = encoder.encodeToString(iv);
  return new AutoValue_ContentCryptographer_Crypted(info, contentBase64, ivBase64);
}
 
開發者ID:square,項目名稱:keywhiz,代碼行數:7,代碼來源:ContentCryptographer.java

示例12: encodeBase64

import java.util.Base64.Encoder; //導入方法依賴的package包/類
/**
 * 對byte做base64編碼
 */
public static String encodeBase64(byte[] data) {
	
	Encoder encoder = Base64.getEncoder();
	return encoder.encodeToString(data);
}
 
開發者ID:pengjieran,項目名稱:OpenTools,代碼行數:9,代碼來源:CodeUtil.java


注:本文中的java.util.Base64.Encoder.encodeToString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。