北邮java智能卡实验报告3des加解密

上传人:l**** 文档编号:134563050 上传时间:2020-06-06 格式:DOC 页数:11 大小:1.49MB
返回 下载 相关 举报
北邮java智能卡实验报告3des加解密_第1页
第1页 / 共11页
北邮java智能卡实验报告3des加解密_第2页
第2页 / 共11页
北邮java智能卡实验报告3des加解密_第3页
第3页 / 共11页
北邮java智能卡实验报告3des加解密_第4页
第4页 / 共11页
北邮java智能卡实验报告3des加解密_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《北邮java智能卡实验报告3des加解密》由会员分享,可在线阅读,更多相关《北邮java智能卡实验报告3des加解密(11页珍藏版)》请在金锄头文库上搜索。

1、智能卡技术实验报告 学院: 电子工程学院班级: 2011211204: 学号: 2011210986实验四 Java卡对称加密解密程序一、实验目的:建立Java卡3DES算法的加密解密程序,并进行Java卡程序的编译和调测。二、实验设备:PC机,智能卡读卡器,Java卡。三、实验容:1. 建立一个JavaCard工程2. 编写3DES算法的加解密应用代码3. 使用智能卡模拟器对应用代码进行调试4. 使用Java卡对应用代码进行编译测试四、实验报告:1. 设计一个3DES算法的加密解密小应用程序2. 画出系统结构图和各部分程序流程图3. 完成程序的开发,然后再在Java卡上进行验证五、流程图系统

2、结构流程:各部分流程图1) 产生随机明文流程图2) 3DES加密流程图 3)3DES解密流程图六、演示模拟器随机产生8字节的明文:D4AA3503EC117A56,用时:1113us加密,密文:DCC74C5B43340FB7,用时:8445us解密,用时:6338us插卡产生明文:09FED7DA8FC3B90F,用时:83990us加密,产生密文:A447987D6FF5CC2C,用时:682482us解密,用时:641494us可以看出,插卡后比直接用模拟器,加密解密的时间长了很多。七、实验总结通过本次智能卡实验,我了解了对称加密的一些相关概念与知识,并学会了如何在智能卡上实现对称加解密

3、。八、源代码package desthree;import javacard.framework.*;import javacard.security.*;import javacardx.crypto.*;public class Desthree extends Appletbyte Random;byte ciphertext=new byte256;byte translation=new byte256;private DESKey deskey;Cipher CipherObj; private byte keyData1=0x01, 0x02, 0x03, 0x04, 0x05,

4、 0x06, 0x07, 0x08;/密钥private byte keyData2=0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18;private byte keyData3=0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28;protected Desthree()register();public static void install(byte bArray, short bOffset, byte bLength)new Desthree();public void process(APDU ap

5、du)throws ISOExceptionbyte buffer = apdu.getBuffer();if(bufferISO7816.OFFSET_CLA)=0 & (bufferISO7816.OFFSET_INS)=(byte)(0xa4)return;if(bufferISO7816.OFFSET_INS=(byte)0x84)getRandom();/返回生成的8字节随机数Util.arrayCopyNonAtomic(Random, (short)0, buffer, (short)0, (short)8);apdu.setOutgoingAndSend(short)0,(sh

6、ort)8);if(bufferISO7816.OFFSET_INS=(byte)0x83)apdu.setIncomingAndReceive();encrypt(buffer); /加密Util.arrayCopyNonAtomic(ciphertext, (short)16, buffer, (short)0, (short)8);apdu.setOutgoingAndSend(short)0,(short)8); if(bufferISO7816.OFFSET_INS=(byte)0x82)apdu.setIncomingAndReceive();doAuthentication(bu

7、ffer); /解密/执行加密过程的代码private void encrypt(byte buffer) deskey = (DESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_DES,KeyBuilder.LENGTH_DES,false);deskey.setKey(keyData1, (short)0);CipherObj = Cipher.getInstance(Cipher.ALG_DES_CBC_ISO9797_M1, false);CipherObj.init(deskey, Cipher.MODE_ENCRYPT);CipherObj.doF

8、inal(buffer, (short)5, (short)8, ciphertext, (short)0);deskey.setKey(keyData2, (short)0);CipherObj = Cipher.getInstance(Cipher.ALG_DES_CBC_ISO9797_M1, false);CipherObj.init(deskey, Cipher.MODE_DECRYPT);CipherObj.doFinal(ciphertext, (short)0, (short)8, ciphertext, (short)8);deskey.setKey(keyData3, (s

9、hort)0);CipherObj = Cipher.getInstance(Cipher.ALG_DES_CBC_ISO9797_M1, false);CipherObj.init(deskey, Cipher.MODE_ENCRYPT);CipherObj.doFinal(ciphertext, (short)8, (short)8, ciphertext, (short)16);/执行解密过程的代码private void doAuthentication(byte buffer)deskey = (DESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_D

10、ES,KeyBuilder.LENGTH_DES,false);deskey.setKey(keyData3, (short)0);CipherObj = Cipher.getInstance(Cipher.ALG_DES_CBC_ISO9797_M1, false);CipherObj.init(deskey, Cipher.MODE_DECRYPT);CipherObj.doFinal(buffer, (short)5, (short)8, translation, (short)0);deskey.setKey(keyData2, (short)0);CipherObj = Cipher

11、.getInstance(Cipher.ALG_DES_CBC_ISO9797_M1, false);CipherObj.init(deskey, Cipher.MODE_ENCRYPT);CipherObj.doFinal(translation, (short)0, (short)8, translation, (short)8);deskey.setKey(keyData1, (short)0);CipherObj = Cipher.getInstance(Cipher.ALG_DES_CBC_ISO9797_M1, false);CipherObj.init(deskey, Ciphe

12、r.MODE_DECRYPT);CipherObj.doFinal(translation, (short)8, (short)8, translation, (short)16);if(Util.arrayCompare(translation, (short)16, Random, (short)0, (short)8)!=0)ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);/获取随机数private void getRandom()if(Random=null)Random = JCSystem.makeTransientByteArray(short)8,JCSystem.CLEAR_ON_DESELECT);RandomData ICC = RandomData.getInstance(byte)RandomData.ALG_PSEUDO_RANDOM);ICC.setSeed(Random, (short)0, (short)8);ICC.generateData(Random, (short)0, (short)8);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 工作范文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号