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


Java BASE64Encoder.encode方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: getImageBase64

import sun.misc.BASE64Encoder; //導入方法依賴的package包/類
public static String getImageBase64(BufferedImage img)  
{
    InputStream in = null;  
    byte[] data = null;  

    try   
    {  
    	ByteArrayOutputStream bs = new ByteArrayOutputStream();  
    	ImageOutputStream imOut = ImageIO.createImageOutputStream(bs); 
    	ImageIO.write(img, "jpg",imOut);
    	
        in = new ByteArrayInputStream(bs.toByteArray());         
        data = new byte[in.available()];  
        in.read(data);  
        in.close();  
        
        imOut.close();
    }   
    catch (IOException e)   
    {  
        e.printStackTrace();  
    }  

    BASE64Encoder encoder = new BASE64Encoder();  
    return encoder.encode(data);
}
 
開發者ID:chengxp3,項目名稱:galaxy,代碼行數:27,代碼來源:ApplicationController.java

示例6: toBase64

import sun.misc.BASE64Encoder; //導入方法依賴的package包/類
/**
    * 將生成的二維碼圖片轉化為base64編碼,直接傳給瀏覽器顯示
    * 好處是可以傳圖片的同時將參數也一並傳遞過去
    * @param content
    * @param width
    * @param height
    * @return
    */
public static String toBase64(String content,int width,int height){
	String qrCodeBASE64 = null;
   	try{
    	BitMatrix bitMatrix = new MultiFormatWriter().encode(content,BarcodeFormat.QR_CODE , width, height);
    	BufferedImage bufferedImage = QRCodeUtil.toBufferedImage(bitMatrix);
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
		ImageIO.write(bufferedImage,"png",byteArrayOutputStream);
		byte[] data = byteArrayOutputStream.toByteArray();
		byteArrayOutputStream.flush();
		byteArrayOutputStream.close();
		BASE64Encoder base64 = new BASE64Encoder();
		qrCodeBASE64 = base64.encode(data);
   	}catch(Exception e){
   		e.printStackTrace();
   	}
   	return qrCodeBASE64;
}
 
開發者ID:leohdr,項目名稱:ScanLogin,代碼行數:26,代碼來源:QRCodeUtil.java

示例7: updatePlayer

import sun.misc.BASE64Encoder; //導入方法依賴的package包/類
public void updatePlayer(Player player) {
    try {
        PreparedStatement prep = connection.prepareStatement("UPDATE players SET username = ?, email = ?, passwordHash = ?, passwordSalt = ?" +
                "WHERE playerID = ?");
        prep.setString(1, player.getUsername());
        prep.setString(2, player.getEmail());
        BASE64Encoder enc = new BASE64Encoder();
        String hash = enc.encode(player.getPasswordHash());
        String salt = enc.encode(player.getPasswordSalt());
        prep.setString(3, hash);
        prep.setString(4, salt);
        prep.setInt(5, player.getId());

        prep.execute();

    } catch (SQLException e) {
        e.printStackTrace();
    }

}
 
開發者ID:KillianMeersman,項目名稱:Geometry-wars,代碼行數:21,代碼來源:PlayerMapper.java

示例8: createCustomCookieValue

import sun.misc.BASE64Encoder; //導入方法依賴的package包/類
private String createCustomCookieValue()
{
	String value = null;
	byte[] buffer = null;
	MessageDigest md = null;
	BASE64Encoder encoder = new BASE64Encoder();

	try
	{
		md = MessageDigest.getInstance("SHA");
		buffer = new Date().toString().getBytes();

		md.update(buffer);
		value = encoder.encode(md.digest());
		original = value;

	} catch (Exception e)
	{
		e.printStackTrace();
	}

	return value;
}
 
開發者ID:RIGS-IT,項目名稱:sonar-xanitizer,代碼行數:24,代碼來源:HttpOnly.java

示例9: getEncString

import sun.misc.BASE64Encoder; //導入方法依賴的package包/類
/**
 * 加密String明文輸入,String密文輸出
 *
 * @param strMing
 * @return
 */
public String getEncString(String strMing) {
	byte[] byteMi = null;
	byte[] byteMing = null;
	String strMi = "";
	BASE64Encoder base64en = new BASE64Encoder();
	try {
		byteMing = strMing.getBytes("UTF8");
		byteMi = getEncCode(byteMing);
		strMi = base64en.encode(byteMi);
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		base64en = null;
		byteMing = null;
		byteMi = null;
	}
	return strMi;
}
 
開發者ID:leopardoooo,項目名稱:cambodia,代碼行數:25,代碼來源:DES.java

示例10: digestPassword

import sun.misc.BASE64Encoder; //導入方法依賴的package包/類
/**
 * 加密
 *
 * @param password 需要加密的字符串
 */
private static String digestPassword(String password) {
    try {
        SecureRandom random = new SecureRandom();
        byte[] salt = new byte[EncodeKit.SALT_SIZE];
        random.nextBytes(salt);

        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(salt);
        md.update(password.getBytes());
        byte[] digest = md.digest();

        BASE64Encoder encoder = new BASE64Encoder();
        return encoder.encode(salt) + encoder.encode(digest);
    } catch (NoSuchAlgorithmException ne) {
        System.err.println(ne.toString());
        return null;
    } catch (Exception e) {
        System.err.println(e.toString());
        return null;
    }
}
 
開發者ID:GojaFramework,項目名稱:goja,代碼行數:27,代碼來源:KeyCodeKit.java

示例11: composeEnvelopeADRB10

import sun.misc.BASE64Encoder; //導入方法依賴的package包/類
private String composeEnvelopeADRB10(byte[] sign, byte[] x509,
		byte[] origHash, Date signingTime) throws Exception {
	X509Certificate cert = loadCert(x509);

	byte[] ret = ccServ.composeBodySha1(sign, cert, origHash, signingTime);

	byte[] hashSa = ccServ
			.hashSignedAttribSha1(origHash, signingTime, cert);

	if (!verifySign(NDX_SHA1, cert, ccServ.calcSha1(hashSa), sign)) {
		throw new InvalidSigntureException();
	}

	BASE64Encoder b64enc = new BASE64Encoder();
	return b64enc.encode(ret);
}
 
開發者ID:bluecrystalsign,項目名稱:signer-source,代碼行數:17,代碼來源:BlucUtil.java

示例12: composeEnvelopeADRB21

import sun.misc.BASE64Encoder; //導入方法依賴的package包/類
private String composeEnvelopeADRB21(byte[] sign, byte[] x509,
		byte[] origHash, Date signingTime) throws Exception {
	X509Certificate cert = loadCert(x509);

	byte[] ret = ccServ
			.composeBodySha256(sign, cert, origHash, signingTime);

	byte[] hashSa = ccServ.hashSignedAttribSha256(origHash, signingTime,
			cert);

	if (!verifySign(NDX_SHA256, cert, ccServ.calcSha256(hashSa), sign)) {
		throw new InvalidSigntureException();
	}

	BASE64Encoder b64enc = new BASE64Encoder();
	return b64enc.encode(ret);
}
 
開發者ID:bluecrystalsign,項目名稱:signer-source,代碼行數:18,代碼來源:BlucUtil.java

示例13: generateToken

import sun.misc.BASE64Encoder; //導入方法依賴的package包/類
public String generateToken(){//���ݵ�ǰʱ�����ֵ�Լ�һ����������õ�һ��Ψһ�������
	String token=System.currentTimeMillis()+new Random().nextInt()+"";
	//�������������һ�£���Ҫ��������ָ��/ժҪ���̶�128λ
	try {//�������128λ����ժҪ��һ�㲽��
		MessageDigest md=MessageDigest.getInstance("md5");
		byte[] md5=md.digest(token.getBytes());
		//Ϊ�˷�ֱֹ�ӹ���string���ص��������������봮����Ҫ����base64���룬����md5�����е�ÿ�����ֽ�ת�����ĸ��ֽڣ������������ֽڱ��浽�ĸ��ֽ���
		//��ô�ĸ��ֽڵ�ÿ���ֽڱ���ԭ�������ֽڵ�6λ����ÿ�����ֽ�תΪ�ĸ��ֽ�֮�����ĸ��ֽڵ����ݵ��ص��ǣ�ÿ���ֽڵ���Чλֻ�Ǻ���λ��ǰ��λ���㣬��ôÿ���ֽڵ�
		//��Χ��00000000--00111111��0~63��,��ôһת�룬��ô�ĸ��ֽڵ�ÿ���ֽڶ�Ӧ���ַ�����������Ϥ�Ŀɼ����ַ�
		BASE64Encoder encoder=new BASE64Encoder();
		
		return encoder.encode(md5);
	} catch (NoSuchAlgorithmException e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:mushroomgithub,項目名稱:ServletStudyDemo,代碼行數:17,代碼來源:FormServlet.java

示例14: getSignature

import sun.misc.BASE64Encoder; //導入方法依賴的package包/類
public static String getSignature(ArrayList<String> paramsList, String apiSecret) {
  Collections.sort(paramsList);
  StringBuilder stringBuilder = new StringBuilder();
  for (String param : paramsList) {
    stringBuilder.append(param);
  }
  String stringToSign = stringBuilder.toString();
  String signature = null;
  try {
    Mac mac = Mac.getInstance(API_MESSAGE_SIGN_ALGO);
    SecretKeySpec secret = new SecretKeySpec(apiSecret.getBytes(), API_MESSAGE_SIGN_ALGO);
    mac.init(secret);
    byte[] digest = mac.doFinal(stringToSign.getBytes());
    BASE64Encoder base64Encoder = new BASE64Encoder();
    signature = base64Encoder.encode(digest);
  } catch (Exception e) {
    Logger.error(e.getMessage());
  }
  return signature.replaceAll("=", "");
}
 
開發者ID:Coderaio,項目名稱:sample-play-angular-app,代碼行數:21,代碼來源:EncryptionUtils.java

示例15: encode

import sun.misc.BASE64Encoder; //導入方法依賴的package包/類
public static final String encode(String string, String salt) {
    if(string == null) {
        throw new RuntimeException("加密失敗,加密內容不能為空");
    }
    if(StringUtils.hasText(salt)) {
        string += salt;
    }
    try {
        MessageDigest md5 =  MessageDigest.getInstance(ALGORITHM);
        BASE64Encoder base64Encoder = new BASE64Encoder();
        return base64Encoder.encode(md5.digest(string.getBytes(CHARSET_NAME)));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:Martion2017,項目名稱:ApplicationDetection,代碼行數:16,代碼來源:MD5Util.java


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