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


Java BASE64Encoder類代碼示例

本文整理匯總了Java中sun.misc.BASE64Encoder的典型用法代碼示例。如果您正苦於以下問題:Java BASE64Encoder類的具體用法?Java BASE64Encoder怎麽用?Java BASE64Encoder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: encrypt

import sun.misc.BASE64Encoder; //導入依賴的package包/類
/**
* 加密
* @param datasource byte[]
* @param password String
* @return byte[]
*/
public static String encrypt(String datasource, String password) {
	try {
		if(StringUtils.trimToNull(datasource) == null){
			return null;
		}
		SecureRandom random = new SecureRandom();
		DESKeySpec desKey = new DESKeySpec(password.getBytes());
		// 創建一個密匙工廠,然後用它把DESKeySpec轉換成
		SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
		SecretKey securekey = keyFactory.generateSecret(desKey);
		// Cipher對象實際完成加密操作
		Cipher cipher = Cipher.getInstance("DES");
		// 用密匙初始化Cipher對象
		cipher.init(Cipher.ENCRYPT_MODE, securekey, random);
		// 現在,獲取數據並加密
		// 正式執行加密操作
		 return new BASE64Encoder().encode(cipher.doFinal(datasource.getBytes()));
		
	} catch (Throwable e) {
		e.printStackTrace();
	}
	return null;
}
 
開發者ID:noseparte,項目名稱:Spring-Boot-Server,代碼行數:30,代碼來源:DES.java

示例2: EncryptId

import sun.misc.BASE64Encoder; //導入依賴的package包/類
private static String EncryptId(String id) {
    byte[] byte1 = "3go8&$8*3*3h0k(2)2".getBytes();
    byte[] byte2 = id.getBytes();
    int byte1Length = byte1.length;
    for (int i = 0; i < byte2.length; i++) {
        byte tmp = byte1[(i % byte1Length)];
        byte2[i] = ((byte) (byte2[i] ^ tmp));
    }
    MessageDigest md5;
    try {
        md5 = MessageDigest.getInstance("MD5");
    } catch (Exception e) {
        e.printStackTrace();
        return "";
    }
    byte[] md5Bytes = md5.digest(byte2);
    String retval = new BASE64Encoder().encode(md5Bytes);
    retval = retval.replace('/', '_');
    retval = retval.replace('+', '-');
    return retval;
}
 
開發者ID:Qrilee,項目名稱:MusicuuApi,代碼行數:22,代碼來源:WyMusic.java

示例3: encodeToString

import sun.misc.BASE64Encoder; //導入依賴的package包/類
/**
 * <pre>
 * 圖片文件轉化為Base64編碼字符串
 *
 * </pre>
 *
 * @param image
 * @param type
 * @return
 */
public static String encodeToString(BufferedImage image, String type) {
    String imageString = null;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    try {
        ImageIO.write(image, type, bos);
        byte[] imageBytes = bos.toByteArray();

        BASE64Encoder encoder = new BASE64Encoder();
        imageString = encoder.encode(imageBytes);

        bos.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return imageString.replaceAll("\\n", "");
}
 
開發者ID:arccode,項目名稱:wechat-pay-sdk,代碼行數:28,代碼來源:ImageUtils.java

示例4: getAppData

import sun.misc.BASE64Encoder; //導入依賴的package包/類
private String getAppData(){

        activeUser = CDI.current().select(ActiveUser.class).get();
        CharSequence http = "http://";
        CharSequence https = "https://";
        AppContext appContext = CDI.current().select(AppContext.class).get();
        Gson gson = new Gson();

        Map map = new HashMap();
        map.put("base_url", requestContext.getBaseURL());
        map.put("base64_url", new BASE64Encoder().encode(requestContext.getBaseURL().getBytes()));
        map.put("simple_base_url", requestContext.getBaseURL().replace(http,"").replace(https,""));
        map.put("deployId",appContext.getDeployId());
        map.put("deployMode",appContext.getDeployMode().toString());
        map.put("csrfToken",activeUser.getCsrfToken());

        return gson.toJson(map);

    }
 
開發者ID:Emerjoin,項目名稱:Hi-Framework,代碼行數:20,代碼來源:HTMLizer.java

示例5: generateTokeCode

import sun.misc.BASE64Encoder; //導入依賴的package包/類
public String generateTokeCode(){  
    String value = System.currentTimeMillis()+new Random().nextInt()+"";  
    //獲取數據指紋,指紋是唯一的  
    try {  
        MessageDigest md = MessageDigest.getInstance("md5");  
        byte[] b = md.digest(value.getBytes());//產生數據的指紋  
        //Base64編碼  
        BASE64Encoder be = new BASE64Encoder();  
        be.encode(b);  
        return be.encode(b);//製定一個編碼  
    } catch (NoSuchAlgorithmException e) {  
        e.printStackTrace();  
    }  
      
    return null;  
}
 
開發者ID:m18507308080,項目名稱:bohemia,代碼行數:17,代碼來源:TokenProcessor.java

示例6: getBase64

import sun.misc.BASE64Encoder; //導入依賴的package包/類
public static String getBase64(String str) {
    byte[] b = null;
    String s = null;
    try {
        b = str.getBytes("utf-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    if (b != null) {
        s = new BASE64Encoder().encode(b);
    }
    return s;
}
 
開發者ID:Liweimin0512,項目名稱:MMall_JAVA,代碼行數:14,代碼來源:Base64GroupTest.java

示例7: SignedJarBuilder

import sun.misc.BASE64Encoder; //導入依賴的package包/類
/**
 * Creates a {@link SignedJarBuilder} with a given output stream, and signing information.
 * <p/>If either <code>key</code> or <code>certificate</code> is <code>null</code> then
 * the archive will not be signed.
 *
 * @param out         the {@link OutputStream} where to write the Jar archive.
 * @param key         the {@link PrivateKey} used to sign the archive, or <code>null</code>.
 * @param certificate the {@link X509Certificate} used to sign the archive, or
 *                    <code>null</code>.
 * @throws IOException
 * @throws NoSuchAlgorithmException
 */
public SignedJarBuilder(OutputStream out, PrivateKey key, X509Certificate certificate)
        throws IOException, NoSuchAlgorithmException {
    mOutputJar = new JarOutputStream(new BufferedOutputStream(out));
    mOutputJar.setLevel(9);
    mKey = key;
    mCertificate = certificate;
    if (mKey != null && mCertificate != null) {
        mManifest = new Manifest();
        Attributes main = mManifest.getMainAttributes();
        main.putValue("Manifest-Version", "1.0");
        main.putValue("Created-By", "1.0 (ApkPatch)");
        mBase64Encoder = new BASE64Encoder();
        mMessageDigest = MessageDigest.getInstance(DIGEST_ALGORITHM);
    }
}
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:28,代碼來源:SignedJarBuilder.java

示例8: createSecureToken

import sun.misc.BASE64Encoder; //導入依賴的package包/類
public static String createSecureToken(String token, String id, String sharedSecret, String data, long curTime)
	throws IOException
{
	if( id == null )
	{
		id = "";
	}

	String time = Long.toString(curTime);
	String toMd5 = token + id + time + sharedSecret;

	StringBuilder b = new StringBuilder();
	b.append(URLEncoder.encode(token, "UTF-8"));
	b.append(':');
	b.append(URLEncoder.encode(id, "UTF-8"));
	b.append(':');
	b.append(time);
	b.append(':');
	b.append(new BASE64Encoder().encode(getMd5Bytes(toMd5)));
	if( data != null && data.length() > 0 )
	{
		b.append(':');
		b.append(data);
	}
	return b.toString();
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:27,代碼來源:TokenSecurity.java

示例9: SignedJarBuilder

import sun.misc.BASE64Encoder; //導入依賴的package包/類
/**
 * Creates a {@link SignedJarBuilder} with a given output stream, and signing information.
 * <p/>If either <code>key</code> or <code>certificate</code> is <code>null</code> then
 * the archive will not be signed.
 * @param out the {@link OutputStream} where to write the Jar archive.
 * @param key the {@link PrivateKey} used to sign the archive, or <code>null</code>.
 * @param certificate the {@link X509Certificate} used to sign the archive, or
 * <code>null</code>.
 * @throws IOException
 * @throws NoSuchAlgorithmException
 */
public SignedJarBuilder(OutputStream out, PrivateKey key, X509Certificate certificate)
        throws IOException, NoSuchAlgorithmException {
    mOutputJar = new JarOutputStream(new BufferedOutputStream(out));
    mOutputJar.setLevel(9);
    mKey = key;
    mCertificate = certificate;

    if (mKey != null && mCertificate != null) {
        mManifest = new Manifest();
        Attributes main = mManifest.getMainAttributes();
        main.putValue("Manifest-Version", "1.0");
        main.putValue("Created-By", "1.0 (Android)");

        mBase64Encoder = new BASE64Encoder();
        mMessageDigest = MessageDigest.getInstance(DIGEST_ALGORITHM);
    }
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:29,代碼來源:SignedJarBuilder.java

示例10: getImageStr

import sun.misc.BASE64Encoder; //導入依賴的package包/類
/**
 * 將圖片文件轉化為字節數組字符串,並對其進行Base64編碼處理
 * @param imgSrcPath 生成64編碼的圖片的路徑
 * @return
 * @throws UnsupportedEncodingException 
 */
public static String getImageStr(String imgSrcPath) throws UnsupportedEncodingException{
    InputStream in = null;
    byte[] data = null;
    
  //讀取圖片字節數組
    try {
        in = new FileInputStream(imgSrcPath);
        data = new byte[in.available()];
        in.read(data);
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    //對字節數組Base64編碼
    BASE64Encoder encoder = new BASE64Encoder();

    return encoder.encode(data);
}
 
開發者ID:Fetax,項目名稱:Fetax-AI,代碼行數:25,代碼來源:ImageAnd64Binary.java

示例11: encodeBase64

import sun.misc.BASE64Encoder; //導入依賴的package包/類
public static String encodeBase64(String str) {
    if (str == null) {
        return null;
    }
    byte[] b;
    String s = null;
    try {
        b = str.getBytes("UTF-8");
    } catch (Exception e) {
        return null;
    }
    if (b != null) {
        s = new BASE64Encoder().encode(b);
    }
    return s;
}
 
開發者ID:baohongfei,項目名稱:think-in-java,代碼行數:17,代碼來源:Base64Util.java

示例12: getData

import sun.misc.BASE64Encoder; //導入依賴的package包/類
public static String getData(String address) {

		StringBuffer buffer = new StringBuffer();
		try {
			URL url = new URL(address);
			URLConnection con = url.openConnection();
			byte[] encodedPassword = "doof:letmein2011".getBytes();
			BASE64Encoder encoder = new BASE64Encoder();
			con.setRequestProperty("Authorization", "Basic " + encoder.encode(encodedPassword));
			BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
			String inputLine;
			while ((inputLine = in.readLine()) != null) {

				buffer.append(inputLine + "\n");
			}
			in.close();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return buffer.toString();
	}
 
開發者ID:GIScience,項目名稱:openrouteservice,代碼行數:22,代碼來源:TrafficUtility.java

示例13: covertImageToBase64

import sun.misc.BASE64Encoder; //導入依賴的package包/類
/**
 *  將圖片文件轉化為字節數組字符串,並對其進行Base64編碼處理
 * @param path	圖片路徑
 * @return
 */
public static String covertImageToBase64(String path) {
	byte [] buf = null;
	// 讀取圖片字節數組
	try {
		InputStream in = new FileInputStream(path);
		buf = new byte[in.available()];
		in.read(buf);
		in.close();
	}catch(IOException e) {
		e.printStackTrace();
	}
	// 對字節數組進行Base64編碼
	BASE64Encoder encoder = new BASE64Encoder();
	return encoder.encode(buf); // 返回Base64編碼字符串
}
 
開發者ID:IaHehe,項目名稱:classchecks,代碼行數:21,代碼來源:ImageUtils.java

示例14: encriptar

import sun.misc.BASE64Encoder; //導入依賴的package包/類
public static String encriptar(String passPhrase, String str)
    throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException
{
    Cipher ecipher = null;
    Cipher dcipher = null;
    java.security.spec.KeySpec keySpec = new PBEKeySpec(passPhrase.toCharArray(), SALT_BYTES, ITERATION_COUNT);
    SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);
    ecipher = Cipher.getInstance(key.getAlgorithm());
    dcipher = Cipher.getInstance(key.getAlgorithm());
    java.security.spec.AlgorithmParameterSpec paramSpec = new PBEParameterSpec(SALT_BYTES, ITERATION_COUNT);
    ecipher.init(1, key, paramSpec);
    dcipher.init(2, key, paramSpec);
    byte utf8[] = str.getBytes("UTF8");
    byte enc[] = ecipher.doFinal(utf8);
    return (new BASE64Encoder()).encode(enc);
}
 
開發者ID:marlonalexis,項目名稱:Multicentro_Mascotas,代碼行數:17,代碼來源:UtilCryptography.java

示例15: createQrcode

import sun.misc.BASE64Encoder; //導入依賴的package包/類
/**
 * 二維碼生成 ,儲存地址qrcodeFilePath
 * 
 * @param text 二維碼內容
 * @return Base64Code String
 */
@SuppressWarnings("restriction")
public String createQrcode(String text){
	String Imgencode="";
       byte[] imageByte=null;
       String formatName="PNG";
       try {
       	//
           int qrcodeWidth = 300;
           int qrcodeHeight = 300;
           HashMap<EncodeHintType, String> hints = new HashMap<EncodeHintType, String>();
           hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
           BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, qrcodeWidth, qrcodeHeight, hints);
          
           ByteArrayOutputStream out = new ByteArrayOutputStream();
           BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
           ImageIO.write(bufferedImage, formatName, out);
           imageByte=out.toByteArray();
           Imgencode = new sun.misc.BASE64Encoder().encode(imageByte);
       } catch (Exception e) {
           e.printStackTrace();
       }
       return Imgencode;
   }
 
開發者ID:noseparte,項目名稱:Spring-Boot-Server,代碼行數:30,代碼來源:Qrcode.java


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