亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

字符數據如何用DES加密

九三
194
2021-02-25 16:32:57
欄目: 網絡安全

字符數據如何用DES加密

在Java中使用DES加密算法對字符數據進行加密,具體方法如下:

public class DesTool {

private static final String PASSKEY = "afasdf";

private static final String DESKEY = "asfsdfsdf";

public static String encoderOrdecoder( String src, int mode) {

String tag="";

InputStream is = null;

OutputStream out = null;

CipherInputStream cis = null;

try {

SecureRandom sr = new SecureRandom();

DESKeySpec dks = new DESKeySpec(DESKEY.getBytes());

SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");

SecretKey securekey = keyFactory.generateSecret(dks);

IvParameterSpec iv = new IvParameterSpec(PASSKEY.getBytes());

Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");

cipher.init(mode, securekey, iv, sr);

cis = new CipherInputStream(new ByteArrayInputStream(src.getBytes()) , cipher);

out=new ByteArrayOutputStream();

byte[] buffer = new byte[1024];

int r;

while ((r = cis.read(buffer)) > 0) {

out.write(buffer, 0, r);

}

tag=out.toString();

} catch (Exception e) {

e.printStackTrace();

} finally {

try {

if (is != null) {

is.close();

}

if (cis != null) {

cis.close();

}

if (out != null) {

out.close();

}

} catch (Exception e1){

}

}

return tag;

}

public static void main(String[] args) {

System.out.println("aaa");

String t=encoderOrdecoder("aaa", Cipher.ENCRYPT_MODE );

System.out.println(t);

System.out.println(encoderOrdecoder(t, Cipher.DECRYPT_MODE ));

}

}

0
益阳市| 琼海市| 安岳县| 茶陵县| 巩留县| 那曲县| 德令哈市| 吉隆县| 化州市| 宜城市| 西乌珠穆沁旗| 民乐县| 兖州市| 龙泉市| 凤翔县| 盖州市| 鹤壁市| 筠连县| 通道| 托克逊县| 印江| 通榆县| 丹寨县| 大同市| 江源县| 抚顺市| 宁蒗| 中卫市| 都匀市| 上林县| 麻城市| 明溪县| 秦皇岛市| 托克逊县| 麻栗坡县| 周宁县| 南陵县| 玛沁县| 洞口县| 满城县| 文登市|