1.java加密的几种方式
2.Java中用Base64编程的文件批量加密解密工具程序代码
3.这个(base64编码)音频数据怎么用?
4.java base64解码 怎么是乱码呢
5.java base64decoder
6.å
³äºsun.misc.BASE64Encoder 解å¯
java加密的几种方式
基本的单向加密算法:BASE 严格地说,属于编码格式,而非加密算法
MD5(Message Digest algorithm 5,淘宝装修工具 源码信息摘要算法)
SHA(Secure Hash Algorithm,安全散列算法)
HMAC(Hash Message Authentication Code,怎么制作游戏源码散列消息鉴别码)
复杂的python 社交网站源码对称加密(DES、PBE)、非对称加密算法:
DES(Data Encryption Standard,数据加密算法)
PBE(Password-based encryption,基于密码验证)
RSA(算法的名字以发明者的名字命名:Ron Rivest, AdiShamir 和Leonard Adleman)
DH(Diffie-Hellman算法,密钥一致协议)
DSA(Digital Signature Algorithm,数字签名)
ECC(Elliptic Curves Cryptography,椭圆曲线密码编码学)
代码参考:
/**
* BASE加密
*
* @param key
* @return
* @throws Exception
*/
public static String encryptBASE(byte[] key) throws Exception {
return (new BASEEncoder()).encodeBuffer(key);
}
/**
* MD5加密
*
* @param data
* @return
* @throws Exception
*/
public static byte[] encryptMD5(byte[] data) throws Exception {
MessageDigest md5 = MessageDigest.getInstance(KEY_MD5);
md5.update(data);
return md5.digest();
}
/**
* SHA加密
*
* @param data
* @return
* @throws Exception
*/
public static byte[] encryptSHA(byte[] data) throws Exception {
MessageDigest sha = MessageDigest.getInstance(KEY_SHA);
sha.update(data);
return sha.digest();
}
}
/**
* 初始化HMAC密钥
*
* @return
* @throws Exception
*/
public static String initMacKey() throws Exception {
KeyGenerator keyGenerator = KeyGenerator.getInstance(KEY_MAC);
SecretKey secretKey = keyGenerator.generateKey();
return encryptBASE(secretKey.getEncoded());
}
/**
* HMAC加密
*
* @param data
* @param key
* @return
* @throws Exception
*/
public static byte[] encryptHMAC(byte[] data,fpga 访问sram源码 String key) throws Exception {
SecretKey secretKey = new SecretKeySpec(decryptBASE(key), KEY_MAC);
Mac mac = Mac.getInstance(secretKey.getAlgorithm());
mac.init(secretKey);
return mac.doFinal(data);
}
Java中用Base编程的文件批量加密解密工具程序代码
/** * BASE解密 * * @param key * @return * @throws Exception */
public static byte[] decryptBASE(String key) throws Exception { return (new BASEDecoder()).decodeBuffer(key); } /** * BASE加密 * * @param key * @return * @throws Exception */ public static String encryptBASE(byte[] key) throws Exception { return (new BASEEncoder()).encodeBuffer(key); }
这个(base编码)音频数据怎么用?
import java.io.File;import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.OutputStream;
import sun.misc.BASEDecoder;
import sun.misc.BASEEncoder;
public class base {
public static String getWAVString(){
File fi = new File("click.wav");
if (!fi.exists())
return "";
byte[] data = null;
try{
InputStream is = new FileInputStream(fi);
data = new byte[is.available()];
is.read(data);
is.close();
}catch(Exception ex){
ex.printStackTrace();
}
BASEEncoder encoder = new BASEEncoder();
return encoder.encode(data);
}
public static void getWAV(){
BASEDecoder decoder = new BASEDecoder();
try{
byte[] data = decoder.decodeBuffer(WAVString);
/*for(int i=0 ;i<data.length;i++){
if (data[i] < 0) {
data[i] += ;
}
}*/
OutputStream out = new FileOutputStream("click_BASE.wav");
out.write(data);
out.flush();
out.close();
}catch(Exception ex){
}
}
public static void main(String[] args){
WAVString = getWAVString();
try{
FileWriter out = new FileWriter("Click_BASEString.txt");
out.write(WAVString);
out.flush();
out.close();
}catch(Exception ex){
}
getWAV();
}
private static String WAVString;
}
java base解码 怎么是乱码呢
会乱码的原因是你的编码不一致导致的php中的urlencode的编码是和系统编码一致的(比如windows默认gb,ubuntu默认utf-8)
所以首先需要确定你的系统编码,之后根据得到的系统编码在调用java的decode方法的时候,将这个编码传入(考虑到你的例子中有繁体字,所以,建议你使用utf-8编码),以下是我使用utf-8编码的例子(php环境是ubuntun下)
java basedecoder
java basedecoderæ¯ä»ä¹ï¼è®©æ们ä¸èµ·äºè§£ä¸ä¸ï¼
decoderæ¯java baseç解ç ï¼å¯ä»¥ç¨Javaç¨å¼è¯è¨æ¥å®æBaseçç¼ç ä¸è§£ç åè½ï¼å¨å®é åºç¨ä¸ï¼Baseé¤äºè½å°Binaryèµæå¯è§åä¹å¤ï¼ä¹å¸¸ç¨æ¥è¡¨ç¤ºå串å å¯è¿åçå 容ã
é£ä¹å¨Javaä¸å¦ä½åBaseçç¼ç ä¸è§£ç ï¼decoderï¼ï¼å¯å为两个æ¶æã
æ©æåæ³ï¼
æ©æå¨Javaä¸åBaseçç¼ç ä¸è§£ç ï¼ä¼ä½¿ç¨å°JDKésun.miscå¥ä»¶ä¸çBASEEncoderåBASEDecoderè¿ä¸¤ä¸ªç±»å«ï¼ç¨æ³å¦ä¸ï¼
final BASEEncoder encoder = new BASEEncoder(); final BASEDecoder decoder = new BASEDecoder(); final String text = "å串æå"; final byte[] textByte = text.getBytes("UTF-8"); //ç¼ç final String encodedText = encoder.encode(textByte); System.out.println(encodedText); //解ç System.out.println(new String(decoder.decodeBuffer(encodedText), "UTF-8"));
åæåæ³ï¼
å¨Java 8çjava.utilå¥ä»¶ä¸ï¼æ°å¢äºBaseçç±»å«ï¼å¯ä»¥ç¨æ¥å¤çBaseçç¼ç ä¸è§£ç ï¼ç¨æ³å¦ä¸ï¼ package com.lmp.utils; import sun.misc.BASEDecoder; import sun.misc.BASEEncoder; public class test { public static void main(String[] args) throws Exception { String str = "hello word"; BASEEncoder baseEncoder = new BASEEncoder(); // JDK1.8 BASEEncoder å å¯ String encode = baseEncoder.encode(str.getBytes()); System.out.println(encode); BASEDecoder baseDecoder = new BASEDecoder(); // JDK1.8 BASEDecoder è§£å¯ byte[] bytes = baseDecoder.decodeBuffer(encode); String res = new String(bytes); System.out.println(res); } }
å ³äºsun.misc.BASEEncoder 解å¯
BASEDecoder
è¿ä¸ªæ²¡æjava docï¼å±äºjdkéä¸æ¨è使ç¨çå·¥å ·ç±»
强ç建议ä¸è¦ç¨sun.miscï¼æ¯ä¸å®å ¨ç ï¼æ好ä¸è¦ä½¿ç¨
解å³æ¹æ¡ï¼
使ç¨apache commonä¸çBaseæ¿æ¢
ä½ å¯ä»¥å¨è¿éä¸è½½Apache commons codec:
mons.apache.org/codec/
2024-11-27 01:03
2024-11-27 01:00
2024-11-27 00:48
2024-11-27 00:15
2024-11-27 00:04
2024-11-26 23:21
2024-11-26 22:35
2024-11-26 22:31