Andriod 的 DES 加密

來源:互聯網
上載者:User

Andriod 的 DES 加密

1主要代碼

關於 des 的導包 問題 要導 安卓本身的 64 位元包 如果找com.sun.....可能會發生foundclass異常


String key;
public DES(String key)
{

this.key =key;
}

public String encrypt(String str) {

byte[] enc = null;
try {
enc = desEncrypt(str, key);
}
catch (Exception ex) {
}

// return new com.e.text.BASE64Encoder().encode(enc);
// return new BASE64Encoder().encode(enc);
return new String (Base64.encode( enc, Base64.DEFAULT));
}
public static byte[] desEncrypt(String message, String key) throws Exception {
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");

DESKeySpec desKeySpec = new DESKeySpec(key.getBytes("UTF-8"));

SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
IvParameterSpec iv = new IvParameterSpec(key.getBytes("UTF-8"));
cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv);

return cipher.doFinal(message.getBytes("UTF-8"));
}

附 demo

http://download.csdn.net/detail/wangchunshun/8180345


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.