android 对称加密和非对称加密,Android开发加密之对称与非对称加密算法使用案例.pdf...
Android開發加密之對稱與非對稱加密算法使用案例
消息摘要
md5:登錄注冊, sha1
對稱加密
? 1.des:Data Encryption Standard,數據加密標準
? 2.aes:Advanced Encryption Standard ,更高級的方式
對稱加密特點:加密速度快,只有一把鑰匙,鑰匙泄露文件就暴露
非對稱加密
? 加密算法:RSA
? 特點:
o 秘鑰對:私鑰和公鑰,秘鑰對不是指定的,系統生成的
o 私鑰自己保留,公鑰可以給別人
o 公鑰加密、使用解密
o 私鑰加密、公鑰解密
o 公鑰互換:兩個組織或者兩個人互換公鑰
o 數字簽名:驗證所屬關系 (驗證私鑰在哪里,舉例:比如使用支付寶支付,
支付寶它會有我們的公鑰)
public class MainActivity extends AppCompatActivity {
private TextView tvResult;
private String data;
private String key;
private boolean isDes;
private boolean isAes;
private boolean isRas;
private String desEncrypt;
private String aesEncrypt;
private String privateKey;
private String publicKey;
private byte[] encryptByPrivateKey;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
initView();
data "我的QQ 密碼:123456";
key ;
initKeyPair();
}
private void initKeyPair() {
try {
//初始化秘鑰對:公鑰和私鑰
Map keyPair RSACrypt.genKeyPair();
privateKey RSACrypt.getPrivateKey(keyPair);
publicKey RSACrypt.getPublicKey(keyPair);
Log.e("result","privateKey "+privateKey);
Log.e("result","publicKey "+publicKey);
} catch (Exception e) {
e.printStackTrace();
}
}
public void des(View v) {
try {
if (!isDes) {//加密
desEncrypt Des.encrypt(data, key);
tvResult.setText("DES 加密:" + desEncrypt);
} else {//解密
String desDecrypt Des.decrypt(desEncrypt, key);
tvResult.setText("DES 解密:" + desDecrypt);
}
isDes !isDes;
} catch (Exception e) {
e.printStackTrace();
}
}
public void aes(View v) {
if
總結
以上是生活随笔為你收集整理的android 对称加密和非对称加密,Android开发加密之对称与非对称加密算法使用案例.pdf...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: “奇心隐仙籍”上一句是什么
- 下一篇: android 自定义 theme,An