MD5是不可逆算法,用DES加密然后用BASE64对加密后的二进制数据进行编码http://www.javayou.com
解决方案 »
- 怎么去深刻理解设计模式?
- 请问"void"是什么意思?
- 背景 png 如何去 毛边
- 怎么样才能使鼠标右键弹出的PopupMenu只发生在JTabbedPane头部?给点思路。
- 新手请教关于hashset!谢谢!请问用Hashset里的remove方法时,删掉的对象是最新
- 请教树图的展开、折叠节点的方法!
- 简单的问题。书上的例题
- 又是一个初学JAVA的小疑问,请帮助我!
- 高人请近来帮我看看,(马上给分)
- 为什么show1可以调用show2?在创建对象的时候加载类Test,此时执行到show1,而show1调用show2,此时的show2并没有在内存中分配空间啊
- 问小问题,up者送分!100分纪念几个重要日子
- 如何知道中文乱码的内容
java.security.MessageDigest alga=java.security.MessageDigest.getInstance("SHA-1");
alga.update(myinfo.getBytes());
byte[] digesta=alga.digest(); //通过某中方式传给其他人你的信息(myinfo)和摘要(digesta) 对方可以判断是否更改或传输正常
java.security.MessageDigest algb=java.security.MessageDigest.getInstance("SHA-1");
algb.update(myinfo.getBytes());
if (algb.isEqual(digesta,algb.digest())) {
System.out.println("信息检查正常");
}
else
{
System.out.println("摘要不相同");
}
package natoni;import java.util.Random;public class SimpleEncoder {
private static Random random = new Random();
public static void main(String[] args){
String s = "hello world";
System.out.println(s+'\n');
byte[] key = getRandomKey(5);
byte[] s1 = encrypt(key,s.getBytes());
System.out.println(new String(s1)+'\n');
byte[] s2 = decrypt(key,s1);
System.out.println(new String(s2)+'\n');
}
public static byte[] getRandomKey(int length) {
if(length <= 0){
throw new IllegalArgumentException();
}
int rand, index=0;
byte[] result = new byte[length];
for(int i=0; i<(length/5); i++){
rand = random.nextInt();
for(int j=0; j<5; j++) {
result[index++] = (byte)(rand&63);
rand >>= 6;
}
}
rand = random.nextInt();
for(int i=0; i<(length%5); i++) {
result[index++] = (byte)(rand&63);
rand >>= 6;
}
return result;
}
public static byte[] encrypt(byte[] key, byte[] b) {
if(key==null || b==null){
throw new IllegalArgumentException();
}
int index = 0;
byte[] result = (byte[])b.clone();
for(int i=0; i<(b.length/key.length); i++){
for(int j=0; j<key.length; j++){
result[index++] += key[j];
}
}
for(int i=0; i<(b.length%key.length); i++){
result[index++] += key[i];
}
return result;
}
public static byte[] decrypt(byte[] key, byte[] b) {
if(key==null || b==null){
throw new IllegalArgumentException();
}
int index = 0;
byte[] result = (byte[])b.clone();
for(int i=0; i<(b.length/key.length); i++){
for(int j=0; j<key.length; j++){
result[index++] -= key[j];
}
}
for(int i=0; i<(b.length%key.length); i++){
result[index++] -= key[i];
}
return result;
}
}
Exception
{
SecretKey k = null;
k = new SecretKeySpec(key_byte, "DESede");
return k;
} public static byte[] desDecrypt(javax.crypto.SecretKey key, byte[] crypt) throws
Exception
{
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(
"DESede");
cipher.init(javax.crypto.Cipher.DECRYPT_MODE, key);
return cipher.doFinal(crypt);
} public static byte[] desEncrypt(javax.crypto.SecretKey key, byte[] src) throws
Exception
{
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(
"DESede");
cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, key);
return cipher.doFinal(src);
}
.-------- 0 .--
/ .......
' ..
'........ ----
. --..
. .---.. -
分 o . ' -.
分 / '
/ ' ' '
\-分--/....... . ' ' ' '
\ __/ - - -' ' ' '
' ' ' '
o ' ' ' '
' ' '
-..'.----------.
I ----------
/////////.