当前位置: 首页>>代码示例>>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;未经允许,请勿转载。