您的位置:首页 > 其它

Package Initilization Performance Research

2013-01-04 14:15 113 查看
DES/CBC/PKCS5Padding 加密解密

 

import java.security.Key;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.IvParameterSpec;

public class MainClass {
public static void main(String args[]) throws Exception {
KeyGenerator kg = KeyGenerator.getInstance("DES");
Cipher c = Cipher.getInstance("DES/CBC/PKCS5Padding");
Key key = kg.generateKey();

c.init(Cipher.ENCRYPT_MODE, key);
byte input[] = "Stand and unfold yourself".getBytes();
byte encrypted[] = c.doFinal(input);
byte iv[] = c.getIV();

IvParameterSpec dps = new IvParameterSpec(iv);
c.init(Cipher.DECRYPT_MODE, key, dps);
byte output[] = c.doFinal(encrypted);
System.out.println(new String(output));
}
}

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: