本文整理匯總了Java中sun.misc.BASE64Decoder類的典型用法代碼示例。如果您正苦於以下問題:Java BASE64Decoder類的具體用法?Java BASE64Decoder怎麽用?Java BASE64Decoder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BASE64Decoder類屬於sun.misc包,在下文中一共展示了BASE64Decoder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: aesDecrypt
import sun.misc.BASE64Decoder; //導入依賴的package包/類
/**
* AES加密字符串
*
* @param content 需要被加密的字符串
* @return 密文
*/
public static String aesDecrypt(String content) {
try {
byte[] encrypted1 = new BASE64Decoder().decodeBuffer(content);
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
SecretKeySpec keyspec = new SecretKeySpec(PASSWORD_KEY.getBytes(), "AES");
IvParameterSpec ivspec = new IvParameterSpec(PASSWORD_KEY.getBytes());
cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec);
String originalString = new String(cipher.doFinal(encrypted1));
int length = originalString.length();
int ch = originalString.charAt(length - 1);
return originalString.substring(0, length - ch);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例2: decodeToImage
import sun.misc.BASE64Decoder; //導入依賴的package包/類
/**
* <pre>
* Base64編碼的字符解碼為圖片
*
* </pre>
*
* @param imageString
* @return
*/
public static BufferedImage decodeToImage(String imageString) {
BufferedImage image = null;
byte[] imageByte;
try {
BASE64Decoder decoder = new BASE64Decoder();
imageByte = decoder.decodeBuffer(imageString);
ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
image = ImageIO.read(bis);
bis.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
return image;
}
示例3: desEncrypt
import sun.misc.BASE64Decoder; //導入依賴的package包/類
public static String desEncrypt(String data){
try
{
if(data==null||data.equals("")){
return "";
}
data=data.trim();
byte[] encrypted1 = new BASE64Decoder().decodeBuffer(data);
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
SecretKeySpec keyspec = new SecretKeySpec(ZFMPWD.getBytes(), "AES");
IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec);
byte[] original = cipher.doFinal(encrypted1);
String originalString = new String(original);
return originalString.trim();
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例4: invokeFunction
import sun.misc.BASE64Decoder; //導入依賴的package包/類
public InvokeFunctionResponse invokeFunction(InvokeFunctionRequest request)
throws ClientException, ServerException {
HttpResponse response = client.doAction(request, CONTENT_TYPE_APPLICATION_STREAM, "POST");
InvokeFunctionResponse invokeFunctionResponse = new InvokeFunctionResponse();
invokeFunctionResponse.setContent(response.getContent());
invokeFunctionResponse.setPayload(response.getContent());
invokeFunctionResponse.setHeader(response.getHeaders());
invokeFunctionResponse.setStatus(response.getStatus());
Map<String, String> headers = response.getHeaders();
if (headers != null && headers.containsKey(HeaderKeys.INVOCATION_LOG_RESULT)) {
try {
String logResult = new String(new BASE64Decoder().decodeBuffer(headers.get(HeaderKeys.INVOCATION_LOG_RESULT)));
invokeFunctionResponse.setLogResult(logResult);
} catch (IOException e) {
throw new ClientException(e);
}
}
return invokeFunctionResponse;
}
示例5: getPublicKeyByText
import sun.misc.BASE64Decoder; //導入依賴的package包/類
/**
* 根據公鑰Cer文本串讀取公鑰
*
* @param pubKeyText
* @return
*/
public static PublicKey getPublicKeyByText(String pubKeyText) {
try {
CertificateFactory certificateFactory = CertificateFactory.getInstance(BaofooRsaConst.KEY_X509);
BufferedReader br = new BufferedReader(new StringReader(pubKeyText));
String line = null;
StringBuilder keyBuffer = new StringBuilder();
while ((line = br.readLine()) != null) {
if (!line.startsWith("-")) {
keyBuffer.append(line);
}
}
Certificate certificate = certificateFactory.generateCertificate(new ByteArrayInputStream(new BASE64Decoder().decodeBuffer(keyBuffer.toString())));
return certificate.getPublicKey();
} catch (Exception e) {
// log.error("解析公鑰內容失敗:", e);
}
return null;
}
示例6: 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();
}
}
}
示例7: get3DESDecrypt
import sun.misc.BASE64Decoder; //導入依賴的package包/類
/**
* 3-DES解密
*
* @param String
* src 要進行3-DES解密的String
* @param String
* spkey分配的SPKEY
* @return String 3-DES加密後的String
*/
public static String get3DESDecrypt(String src, String spkey) {
String requestValue = "";
try {
// 得到3-DES的密鑰匙
// URLDecoder.decodeTML控製碼進行轉義的過程
String URLValue = getURLDecoderdecode(src);
// 進行3-DES加密後的內容進行BASE64編碼
BASE64Decoder base64Decode = new BASE64Decoder();
byte[] base64DValue = base64Decode.decodeBuffer(URLValue);
// 要進行3-DES加密的內容在進行/"UTF-16LE/"取字節
requestValue = deCrypt(base64DValue, spkey);
} catch (Exception e) {
e.printStackTrace();
}
return requestValue;
}
示例8: 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;
}
}
示例9: getJCas
import sun.misc.BASE64Decoder; //導入依賴的package包/類
public JCas getJCas()
throws RuntimeException
{
if (base64JCas == null) {
return null;
}
try {
byte[] bytes = new BASE64Decoder()
.decodeBuffer(new ByteArrayInputStream(base64JCas.getBytes("utf-8")));
JCas jCas = JCasFactory.createJCas();
XmiCasDeserializer.deserialize(new ByteArrayInputStream(bytes), jCas.getCas());
return jCas;
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
示例10: 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();
}
}
}
示例11: 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;
}
示例12: 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;
}
示例13: desencriptar
import sun.misc.BASE64Decoder; //導入依賴的package包/類
public static String desencriptar(String passPhrase, String str)
throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IOException, IllegalBlockSizeException, BadPaddingException
{
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 dec[] = (new BASE64Decoder()).decodeBuffer(str);
byte utf8[] = dcipher.doFinal(dec);
return new String(utf8, "UTF8");
}
示例14: decrypt
import sun.misc.BASE64Decoder; //導入依賴的package包/類
/**
* 解密
* @param src byte[]
* @param password String
* @return String
* @throws Exception
*/
public static String decrypt(String decodeStr, String password) throws Exception {
byte[] str=new BASE64Decoder().decodeBuffer(decodeStr);
// DES算法要求有一個可信任的隨機數源
SecureRandom random = new SecureRandom();
// 創建一個DESKeySpec對象
DESKeySpec desKey = new DESKeySpec(password.getBytes());
// 創建一個密匙工廠
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
// 將DESKeySpec對象轉換成SecretKey對象
SecretKey securekey = keyFactory.generateSecret(desKey);
// Cipher對象實際完成解密操作
Cipher cipher = Cipher.getInstance("DES");
// 用密匙初始化Cipher對象
cipher.init(Cipher.DECRYPT_MODE, securekey, random);
// 真正開始解密操作
byte[] passByte=cipher.doFinal(str);
return new String(passByte);
}
示例15: AESDecryptor
import sun.misc.BASE64Decoder; //導入依賴的package包/類
public AESDecryptor() {
try
{
/* Derive the key, given password and salt. */
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
KeySpec spec;
spec = new PBEKeySpec(Constants.FRAMEWORK_NAME.toCharArray(), SALT, ITERATIONS, KEY_SIZE);
SecretKey tmp = factory.generateSecret(spec);
secret = new SecretKeySpec(tmp.getEncoded(), "AES");
// CBC = Cipher Block chaining
// PKCS5Padding Indicates that the keys are padded
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
// For production use commons base64 encoder
base64Decoder = new BASE64Decoder();
}
catch (Exception e)
{
throw new RuntimeException("Unable to initialize AESDecryptor", e);
}
}