如題,因為要傳迗變數給另一個apk 使用,基於安全考量才用3DES來做加解密的動作,使用方式如下

下載連結:https://www.dropbox.com/s/7kkha7ztblztav8/arcTools.jar

 

加密

Bundle bundle = new Bundle(); 

try {
Des3.createSecretKey();
Log.d(TAG, "account:"+User.account);
String enAccount = Des3.encode(User.account);
bundle.putString(BundleKey.APK_ACCOUNT, enAccount);
Log.d(TAG, "password:"+User.password);
String enPassword = Des3.encode(User.password);
bundle.putString(BundleKey.APK_PASSWORD, enPassword);
Log.d(TAG, "host:"+User.host);
String enHost = Des3.encode(User.host);
bundle.putString(BundleKey.APK_HOST, enHost);
} catch (Exception e) {
Log.d(TAG, "Exception:"+e.getMessage());
}
intent.putExtras(bundle);

 

解密

Bundle bundle = AutoLoginActivity.this.getIntent().getExtras();
String account = "";
String password = "";
String host = "";
try {
Des3.createSecretKey();
String enAccount = bundle.getString(BundleKey.APK_ACCOUNT);
String enPassword = bundle.getString(BundleKey.APK_PASSWORD);
String enHost = bundle.getString(BundleKey.APK_HOST);
account = Des3.decode(enAccount);
password = Des3.decode(enPassword);
host = Des3.decode(enHost);
String info = account+","+password+","+host;
if (!info.equals("")) {
Toast.makeText(AutoLoginActivity.this, "get TaskName:"+info, Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Log.d(TAG, "Exception:"+e.getMessage());
}

arrow
arrow
    文章標籤
    3DES 加密 解密 技術
    全站熱搜

    狼翔月影 發表在 痞客邦 留言(0) 人氣()