本文整理汇总了Java中sun.misc.BASE64Decoder.decodeBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java BASE64Decoder.decodeBuffer方法的具体用法?Java BASE64Decoder.decodeBuffer怎么用?Java BASE64Decoder.decodeBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.misc.BASE64Decoder
的用法示例。
在下文中一共展示了BASE64Decoder.decodeBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFromTokenStr
import sun.misc.BASE64Decoder; //导入方法依赖的package包/类
public void getFromTokenStr(String tokenStr) {
byte[] b;
String result;
if (tokenStr != null) {
BASE64Decoder decoder = new BASE64Decoder();
try {
b = decoder.decodeBuffer(URLDecoder.decode(tokenStr,"utf-8"));
result = new String(b, "utf-8");
String[] list = result.split("::");
this.userId = list[0];
this.username = list[1];
String lo = list[2];
this.startTime = Long.valueOf(lo);
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例2: generateImage
import sun.misc.BASE64Decoder; //导入方法依赖的package包/类
/**
* 对字节数组字符串进行Base64解码并生成图片
* @param imgStr 转换为图片的字符串
* @param imgCreatePath 将64编码生成图片的路径
* @return
*/
public static boolean generateImage(String imgStr, String imgCreatePath){
if (imgStr == null) //图像数据为空
return false;
BASE64Decoder decoder = new BASE64Decoder();
try {
//Base64解码
byte[] b = decoder.decodeBuffer(imgStr);
for(int i=0;i<b.length;++i) {
if(b[i] < 0) {//调整异常数据
b[i] += 256;
}
}
OutputStream out = new FileOutputStream(imgCreatePath);
out.write(b);
out.flush();
out.close();
return true;
} catch (Exception e){
return false;
}
}
示例3: generateImage
import sun.misc.BASE64Decoder; //导入方法依赖的package包/类
private static void generateImage(String imgStr,String path,String newFileName,String ext){
if (imgStr != null) {
int p = imgStr.indexOf(",");
String head = imgStr.substring(0, p);
String datas = imgStr.substring(p + 1);
System.out.println("FULL-Path:" + path + "\\" + newFileName + "." + ext);
BASE64Decoder decoder = new BASE64Decoder();
try {
// 解密
byte[] b = decoder.decodeBuffer(datas);
// 处理数据
for (int i = 0; i < b.length; ++i) {
if (b[i] < 0) {
b[i] += 256;
}
}
OutputStream out1 = new FileOutputStream(path + "\\" + newFileName + "." + ext);
out1.write(b);
out1.flush();
out1.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例4: convertBase64ToImage
import sun.misc.BASE64Decoder; //导入方法依赖的package包/类
/**
* 对字节数组字符串进行Base64解码并生成图片
* @param base64 图像的Base64编码字符串
* @param fileSavePath 图像要保存的地址
* @return
*/
public static boolean convertBase64ToImage(String base64, String fileSavePath) {
if(base64 == null) return false;
BASE64Decoder decoder = new BASE64Decoder();
// Base64解码
try {
byte[] buffer = decoder.decodeBuffer(base64);
for(int i = 0; i < buffer.length; i ++) {
if(buffer[i] < 0) {
buffer[i] += 256;
}
}
// 生成JPEG图片
OutputStream out = new FileOutputStream(fileSavePath);
out.write(buffer);
out.flush();
out.close();
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
示例5: decodeBase64
import sun.misc.BASE64Decoder; //导入方法依赖的package包/类
public static String decodeBase64(String s) {
if (s == null) {
return null;
}
byte[] b;
String result = null;
if (s != null) {
BASE64Decoder decoder = new BASE64Decoder();
try {
b = decoder.decodeBuffer(s);
result = new String(b, "UTF-8");
} catch (Exception e) {
return null;
}
}
return result;
}
示例6: getFromBase64
import sun.misc.BASE64Decoder; //导入方法依赖的package包/类
/**
* Base64解密
* @param s
* @return
*/
public static String getFromBase64(String s) {
byte[] b;
String result = null;
if (s != null) {
BASE64Decoder decoder = new BASE64Decoder();
try {
b = decoder.decodeBuffer(s);
result = new String(b, "utf-8");
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
return result;
}
示例7: unionPayWapNotify
import sun.misc.BASE64Decoder; //导入方法依赖的package包/类
public static String unionPayWapNotify(Map<String, String> p) {
BASE64Decoder decoder = new BASE64Decoder();
String req = p.get("notifyBody");
String[] strArr = req.split("\\|");
String cerPath = CertUtil.getCertPath("UNIONPAYWAP_USER_Notify_CRT");
String publicKey = EncDecUtil.getPublicCertKey("000000", cerPath);
String content = null;
try {
String mm = RSACoder.decryptByPublicKey(strArr[1], publicKey);
byte[] de = decoder.decodeBuffer(strArr[2]);
byte[] b = DesUtil2.decrypt(de, mm.getBytes());
content = new String(b, "utf-8");
LogUtil.printInfoLog("UnionPayWap", "unionPayWapNotify", content);
} catch (Exception e) {
StringWriter trace = new StringWriter();
e.printStackTrace(new PrintWriter(trace));
LogUtil.printErrorLog("UnionPayWap", "unionPayWapNotify", trace.toString());
}
return content;
}
示例8: readCiphersFromDisk
import sun.misc.BASE64Decoder; //导入方法依赖的package包/类
public static byte[][] readCiphersFromDisk(String filePath) {
try {
File f = new File(filePath);
FileInputStream bais = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(bais);
ObjectInputStream ois = new ObjectInputStream(bis);
String[] encodedCiphers = (String[]) ois.readObject();
ois.close();
byte[][] ciphers = new byte[encodedCiphers.length][];
BASE64Decoder decoder = new BASE64Decoder();
for (int i = 0; i < ciphers.length; i++)
ciphers[i] = decoder.decodeBuffer(encodedCiphers[i]);
return ciphers;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例9: composeBodySha256
import sun.misc.BASE64Decoder; //导入方法依赖的package包/类
public byte[] composeBodySha256(List<AppSignedInfo> listAsi) throws Exception {
byte[] ret = null;
int idSha = NDX_SHA256;
List<AppSignedInfoEx> listAsiEx = new ArrayList<AppSignedInfoEx>();
// List<X509Certificate> chain = new ArrayList<X509Certificate>();
BASE64Decoder b64dec = new BASE64Decoder();
for (AppSignedInfo appSignedInfo : listAsi) {
// AppSignedInfo appSignedInfo = listAsi.get(0);
byte[] x509 = b64dec.decodeBuffer(appSignedInfo.getCertId());
X509Certificate cert = loadCert(x509);
byte[] certHash = calcSha256(cert.getEncoded());
AppSignedInfoEx asiEx = new AppSignedInfoEx(appSignedInfo, cert,
certHash, idSha);
listAsiEx.add(asiEx);
}
ret = serv2048.buildCms(listAsiEx, -1);
return ret;
}
示例10: decodeFromBASE64
import sun.misc.BASE64Decoder; //导入方法依赖的package包/类
/**
* 将 BASE64 编码的字符串 s 进行解码
*
* @param s
* @param charSet
* @return
*/
public final static String decodeFromBASE64(String s, String charSet)
{
String decodedStr;
if (StringUtils.trimToEmpty(s).equals(""))
return "";
BASE64Decoder decoder = new BASE64Decoder();
try
{
byte[] b = decoder.decodeBuffer(s);
if (StringUtils.trimToEmpty(charSet).equals(""))
decodedStr = new String(b);
else
decodedStr = new String(b, charSet);
return decodedStr;
}
catch (Exception e)
{
LogUtil.getAppLog().error("decodeFromBASE64 Error for the string: " + s + "with CharSet " + charSet, e);
return "";
}
}
示例11: validate
import sun.misc.BASE64Decoder; //导入方法依赖的package包/类
@POST
@Path("/validate")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response validate(ValidateRequest req) throws Exception {
ValidateResponse resp = new ValidateResponse();
try {
BASE64Decoder b64dec = new BASE64Decoder();
byte[] sign = b64dec.decodeBuffer(req.getEnvelope());
byte[] sha1 = b64dec.decodeBuffer(req.getSha1());
byte[] sha256 = b64dec.decodeBuffer(req.getSha256());
Date dtSign = javax.xml.bind.DatatypeConverter.parseDateTime(
req.getTime()).getTime();
boolean verifyCRL = "true".equals(req.getCrl());
int errorCode = util.validateSign(sign, sha1, sha256, dtSign, verifyCRL, resp);
resp.setErrorCode(errorCode);
return Response.status(200).entity(resp).build();
} catch (Exception e) {
resp.setError(e.toString());
return Response.status(500).entity(resp).build();
}
}
示例12: decodeToImage
import sun.misc.BASE64Decoder; //导入方法依赖的package包/类
private BufferedImage decodeToImage(String imageString) throws IOException{
BufferedImage image = null;
ByteArrayInputStream bis = null;
byte[] imageByte;
try {
BASE64Decoder decoder = new BASE64Decoder();
imageByte = decoder.decodeBuffer(imageString);
bis = new ByteArrayInputStream(imageByte);
image = ImageIO.read(bis);
} finally {
if(bis != null) {
try {
bis.close();
} catch (IOException e) {
log.error("Error occurred while closing the input stream", e);
}
}
}
return image;
}
示例13: decrypt
import sun.misc.BASE64Decoder; //导入方法依赖的package包/类
/**
* 解密算法
*
* @param cryptograph 密文
* @return
* @throws Exception
*/
private static String decrypt(String cryptograph) throws Exception {
Key privateKey;
ObjectInputStream ois = null;
try {
/** 将文件中的私钥对象读出 */
ois = new ObjectInputStream(new FileInputStream(
PRIVATE_KEY_FILE));
privateKey = (Key) ois.readObject();
} catch (Exception e) {
throw e;
} finally {
ois.close();
}
/** 得到Cipher对象对已用公钥加密的数据进行RSA解密 */
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, privateKey);
BASE64Decoder decoder = new BASE64Decoder();
byte[] b1 = decoder.decodeBuffer(cryptograph);
/** 执行解密操作 */
byte[] b = cipher.doFinal(b1);
return new String(b);
}
示例14: readPrivateKey
import sun.misc.BASE64Decoder; //导入方法依赖的package包/类
public static PrivateKey readPrivateKey(File keyFile) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
// read key bytes
FileInputStream in = new FileInputStream(keyFile);
byte[] keyBytes = new byte[in.available()];
in.read(keyBytes);
in.close();
String privateKey = new String(keyBytes, "UTF-8");
privateKey = privateKey.replaceAll("(-+BEGIN RSA PRIVATE KEY-+\\r?\\n|-+END RSA PRIVATE KEY-+\\r?\\n?)", "");
// don't use this for real projects!
BASE64Decoder decoder = new BASE64Decoder();
keyBytes = decoder.decodeBuffer(privateKey);
// generate private key
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
return keyFactory.generatePrivate(spec);
}
示例15: decrypt
import sun.misc.BASE64Decoder; //导入方法依赖的package包/类
public String decrypt(String encryptedString) throws EncryptionException {
if (encryptedString == null || encryptedString.trim().length() <= 0)
throw new IllegalArgumentException("encrypted string was null or empty");
try {
SecretKey key = keyFactory.generateSecret(keySpec);
cipher.init(Cipher.DECRYPT_MODE, key);
BASE64Decoder base64decoder = new BASE64Decoder();
byte[] cleartext = base64decoder.decodeBuffer(encryptedString);
byte[] ciphertext = cipher.doFinal(cleartext);
return bytes2String(ciphertext);
} catch (Exception e) {
throw new EncryptionException(e);
}
}