本文整理汇总了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", "");
}
示例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;
}
示例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);
}
示例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编码字符串
}
示例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);
}
示例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;
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例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);
}
示例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);
}
示例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);
}
}
示例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("=", "");
}
示例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);
}
}