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