91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

字符數據如何用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
枣庄市| 县级市| 中江县| 宝应县| 丁青县| 肇源县| 平江县| 海阳市| 阿克陶县| 武宣县| 景德镇市| 南皮县| 桂阳县| 潼南县| 双城市| 西林县| 共和县| 弋阳县| 洛宁县| 湟中县| 渭南市| 黄龙县| 正宁县| 丹巴县| 西昌市| 临颍县| 禹城市| 土默特左旗| 巴青县| 郯城县| 辉南县| 敦煌市| 平江县| 巴彦县| 黎平县| 太和县| 新源县| 巩义市| 海原县| 化德县| 梓潼县|