本文整理匯總了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);
}
}