package com.example.datatest;import java.security.KeyPair;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EdgeEffect;import android.widget.EditText;import android.widget.TextView;import android.widget.Toast;import android.renderscript.Element.DataKind;import android.support.v4.app.NavUtils;public class MainActivity extends Activity implements OnClickListener {private KeyPair mKeyPair;private String mRsaData;private String dsaData;private String mData;private String mDsaData;private String desData;private KeyPair mDasKeyPair;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initLayout();}private void initLayout() {// TODO Auto-generated method stubButton button1 = (Button) findViewById(R.id.button1);Button button2 = (Button) findViewById(R.id.button2);Button button3 = (Button) findViewById(R.id.button3);Button button4 = (Button) findViewById(R.id.button4);Button button5 = (Button) findViewById(R.id.button5);Button button6 = (Button) findViewById(R.id.button6);Button button7 = (Button) findViewById(R.id.button7);Button button8 = (Button) findViewById(R.id.button8);Button button9 = (Button) findViewById(R.id.button9);Button button10 = (Button) findViewById(R.id.button10);Button button11 = (Button) findViewById(R.id.button11);Button button12 = (Button) findViewById(R.id.button12);button1.setOnClickListener(this);button2.setOnClickListener(this);button3.setOnClickListener(this);button4.setOnClickListener(this);button5.setOnClickListener(this);button6.setOnClickListener(this);button7.setOnClickListener(this);button8.setOnClickListener(this);button9.setOnClickListener(this);button10.setOnClickListener(this);button11.setOnClickListener(this);button12.setOnClickListener(this);}@Overridepublic void onClick(View v) {// TODO Auto-generated method stubswitch (v.getId()) {case R.id.button1:test1();break;case R.id.button2:test2();break;case R.id.button3:test3();break;case R.id.button4:test4();break;case R.id.button5:test5();break;case R.id.button6:test6();break;case R.id.button7:test7();break;case R.id.button8:test8();break;case R.id.button9:test9();break;case R.id.button10:test10();break;case R.id.button11:test11();break;case R.id.button12:test12();break;default:break;}}private void test12() {// TODO Auto-generated method stubEditText editText12 = (EditText) findViewById(R.id.editText12);String key = editText12.getEditableText().toString();EditText editText13 = (EditText) findViewById(R.id.editText13);if (key.length() != 8) {Toast.makeText(this, "钥匙必须是八位字符", Toast.LENGTH_SHORT).show();} else {String data = DataUtil.decryptDESStr(desData, key);if (data == null) {editText13.setText("钥匙不正确");Toast.makeText(this, "钥匙不正确", Toast.LENGTH_SHORT).show();} else {editText13.setText(data);}}}private void test11() {// TODO Auto-generated method stubEditText editText11 = (EditText) findViewById(R.id.editText11);String key = editText11.getEditableText().toString();EditText editText10 = (EditText) findViewById(R.id.editText10);String data = editText10.getEditableText().toString();if (key.length() != 8) {Toast.makeText(this, "钥匙必须是八位字符", Toast.LENGTH_SHORT).show();} else {desData = DataUtil.encryptDESStr(data, key);editText10.setText(desData);}}private void test10() {// TODO Auto-generated method stubif (mData != null && mDsaData != null) {if (DataUtil.verificationPublicKeyDSA(mData,mDasKeyPair.getPublic(), mDsaData)) {Toast.makeText(this, "这是你写的东西", Toast.LENGTH_SHORT).show();} else {Toast.makeText(this, "这不是你写的东西", Toast.LENGTH_SHORT).show();}}}private void test9() {// TODO Auto-generated method stubEditText editText8 = (EditText) findViewById(R.id.editText8);mData = editText8.getEditableText().toString();mDasKeyPair = DataUtil.getKeyCase("DSA", 512);mDsaData = DataUtil.signetPrivateKeyDSAStr(mData,mDasKeyPair.getPrivate());editText8.setText(mDsaData);}private void test8() {// TODO Auto-generated method stubEditText editText7 = (EditText) findViewById(R.id.editText7);String str = editText7.getEditableText().toString();editText7.setText(DataUtil.decryptPublicKeyStr(mRsaData,mKeyPair.getPublic(), "RSA"));}private void test7() {// TODO Auto-generated method stubEditText editText6 = (EditText) findViewById(R.id.editText6);String str = editText6.getEditableText().toString();mKeyPair = DataUtil.getKeyCase("RSA", 1024);mRsaData = DataUtil.encryptPrivateKeyStr(str, mKeyPair.getPrivate(),"RSA");editText6.setText(mRsaData);}private void test6() {// TODO Auto-generated method stubEditText editText5 = (EditText) findViewById(R.id.editText5);String str = editText5.getEditableText().toString();String key = "eoeandroid";editText5.setText(DataUtil.getEncryptHMACMD5(str, key));}private void test5() {// TODO Auto-generated method stubEditText editText4 = (EditText) findViewById(R.id.editText4);String str = editText4.getEditableText().toString();editText4.setText(DataUtil.encryptDataReversible(str));}private void test4() {// TODO Auto-generated method stubEditText editText3 = (EditText) findViewById(R.id.editText3);String str = editText3.getEditableText().toString();editText3.setText(DataUtil.encyptData2SHA(str));}private void test3() {// TODO Auto-generated method stubEditText editText2 = (EditText) findViewById(R.id.editText2);String str = editText2.getEditableText().toString();editText2.setText(DataUtil.encryptData2MD5(str));}private void test2() {// TODO Auto-generated method stubEditText editText1 = (EditText) findViewById(R.id.editText1);String str = editText1.getEditableText().toString();int len = Integer.valueOf(str);TextView textView4 = (TextView) findViewById(R.id.textView4);textView4.setText(DataUtil.generateStr(len,DataUtil.LOWER_CHINA_NUMBER_CHAR));}private void test1() {// TODO Auto-generated method stubTextView textView1 = (TextView) findViewById(R.id.textView1);textView1.setText(DataUtil.getOnlyStr());}}
下载android 加密解密示例源码用户还喜欢
- 18480 文章数
- 500万+ 热度
作者专栏
编辑推荐
- 淡抹u2引擎,修复内容较多,物有所值
- 界域传说·经典巨作=传世单机(一键安装)
- 丸子版本(175个传世版本大集合)
- GS版本:神话公益服务端+客户端
- 图片放大工具(放大图片不模糊)
- 剪映无限制VIP版
- 传奇世界客户端下载器,史上最全传世客户端
- 传世GS20220920商业引擎注册+登录配置器 解压密码是1
- U2官方排行榜游戏网关 支持元神,支持传家宝
- GS开战传世客户端+服务端
- (淡漠夕阳)u2引擎合区工具
- 传世GS引擎消除“你的游戏客户端版本号过旧,请及时更新”提示
- 传世一机多区双线路配置器--免密码版本
- 传世凤凰登陆器劫持修复软件
- SQLite3 for Navicat
- 传奇世界npc对话框编辑工具
- 传世GS落霞铭文服务器端
- gs_20210409引擎包+注册机(无限制)
- 传奇世界NPC对话封包查看器[支持时长版和极速版]
- 彩虹引擎传世脚本编辑工具1.7版来了,支持函数脚本翻译
评论