当前位置: 首页 > news >正文

网站建设百度文库营销推广有哪些公司

网站建设百度文库,营销推广有哪些公司,网站 自助建站,威客网站开发需求文章目录 前言一、定义接口二、server端实现三、client端实现四、遇到的问题 前言 在进行开发时,可能会将业务放到不同的applet中,这时常常会需要进行数据的分享。 比如在一个applet中存储了密钥,而在另一个业务applet中需要进行签名时&…

文章目录

  • 前言
  • 一、定义接口
  • 二、server端实现
  • 三、client端实现
  • 四、遇到的问题


前言

在进行开发时,可能会将业务放到不同的applet中,这时常常会需要进行数据的分享。
比如在一个applet中存储了密钥,而在另一个业务applet中需要进行签名时,需要将数据传给第一个applet进行签名后,再返回签名后的数据。
这里介绍Java Card中的Shareable的数据分享的方式。

一、定义接口

import javacard.framework.Shareable;public interface DataShareable extends Shareable {public byte getDataInfo(byte[] buffer, short offset, short length);
}

需要继承Java Card的Shareable 类,定义好我们需要的接口,这里定义了getDataInfo方法,用于将数据写到buffer中以提供给client。

二、server端实现

public class DataInfoApplet extends Applet implements DataShareable{byte[] DataInfo;protected DataInfoApplet () {DataInfo = new byte[16];register();}public static void install(byte[] bArray, short bOffset, byte bLength) {new DataInfoApplet ();}@Overridepublic Shareable getShareableInterfaceObject(AID clientAID, byte parameter) {if (!clientAID.equals(sAIDClientApplet, (short) 0, (byte) sAIDClientApplet.length)) {return null;}return this;}@Overridepublic void process(APDU apdu) {}@Overridepublic byte getDataInfo(byte[] out, short offset, short length) {try {Util.arrayCopy(DataInfo, (short) 0, out, offset, length);return OK;} catch (ArrayIndexOutOfBoundsException e) {return NOT_OK;}}
}
  • server端需要实现DataShareable接口。
  • 需要实现getShareableInterfaceObject,该方法会在client端调用JCSystem.getShareableInterfaceObject时执行。在这里面可以进行clientAID的判断,以使得仅有特定的applet才能够调用shareable接口。

三、client端实现

注意:client和server是在不同的package中的。

public class ClientApplet extends Applet {DataShareable sio = null;protected ClientApplet () {register();}public static void install(byte[] bArray, short bOffset, byte bLength) {new ClientApplet ();}private boolean getSIO() {if (this.sio == null) {this.sio = (DataShareable)JCSystem.getAppletShareableInterfaceObject(JCSystem.lookupAID(DATAINFO_APPLET_AID_BYTES,(short)0, (byte)(DATAINFO_APPLET_AID_BYTES.length)),(byte)0);}if(this.sio != null) {return true;} else {return false;}}@Overridepublic void process(APDU apdu) {byte[] buffer = apdu.getBuffer();sio.getDataInfo(buffer , (short) 0, (short) 16);apdu.setOutgoing();apdu.setOutgoingLength((short) 16);apdu.sendBytesLong(buffer , (short) 0, (short) 16);return;}@Overridepublic boolean select() {return getSIO();}@Overridepublic void deselect() {sio = null;}
}
  • getSIO中通过JCSystem.getAppletShareableInterfaceObject来获得接口对象sio。
  • 使用sio来调用接口方法,并传入buffer参数。

四、遇到的问题

1、接口中创建对象失败

@Overridepublic byte getDataInfo(byte[] out, short offset, short length) {try {byte[] temp = JCSystem.makeTransientByteArray((short) 4, JCSystem.CLEAR_ON_DESELECT);Util.arrayCopy(DataInfo, (short) 0, out, offset, length);return OK;} catch (ArrayIndexOutOfBoundsException e) {return NOT_OK;}}

在server实现的接口方法中,添加了byte[] temp = JCSystem.makeTransientByteArray((short) 4, JCSystem.CLEAR_ON_DESELECT);则调用该接口时会报错。

分析:

JCCRE中规定,对于CLEAR_ON_DESELECT类型的瞬态数据,只有当前活动的context是当前选择的applet的context时,才能够创建和使用。

这个案例中,对于两个不同package中的applet进行接口调用时,会进行context的切换,所以调用到getDataInfo接口时,当前活动的context已经切换为了server的context。但是接口是在client处理apdu请求时调用的,此时被选择的applet仍然是client。所以导致前面的条件无法满足,所以出现错误。
在这里插入图片描述
解决:
使用CLEAR_ON_RESET。

byte[] temp = JCSystem.makeTransientByteArray((short) 4, JCSystem.CLEAR_ON_RESET);

CLEAR_ON_RESET类型要求,当前活动的context是对象所有者的context,因此可以在这样的情况下满足条件

2、数据无法通过接口传输

 @Overridepublic void process(APDU apdu) {//byte[] buffer = apdu.getBuffer();byte[] data = JCSystem.makeTransientByteArray((short) 16, JCSystem.CLEAR_ON_RESET);sio.getDataInfo(data , (short) 0, (short) 16);apdu.setOutgoing();apdu.setOutgoingLength((short) 16);apdu.sendBytesLong(data , (short) 0, (short) 16);return;}

如果client中这样写,即使用makeTransientByteArray来创建瞬态数据data并作为参数传递,则调用时会出现数据的访问失败

分析:
在这里插入图片描述
从日志可以看出,是由于临时数据无法在不同的context之间进行访问。临时数据是收到防火墙保护的,这个data数据是属于client的context的,而调用接口后,活动的context切换为了server的context,那么在server中就无法访问这个data,进而无法向其中写入数据。

解决:
使用byte[] buffer = apdu.getBuffer();来进行数据的发送和接收。

 @Overridepublic void process(APDU apdu) {byte[] buffer = apdu.getBuffer();sio.getDataInfo(data , (short) 0, (short) 16);apdu.setOutgoing();apdu.setOutgoingLength((short) 16);apdu.sendBytesLong(data , (short) 0, (short) 16);return;}

apdu.getBuffer() 返回的是 APDU缓冲区,它是一个特殊的 全局缓冲区,在 Java Card 上被认为是跨防火墙允许的共享对象。

http://www.qdjiajiao.com/news/5425.html

相关文章:

  • 夷陵区住房和城乡建设局网站优网营销
  • 实训做网站收获个人网站制作流程
  • 标准型网站---北京网站建设西安网站建设制作公司
  • 深圳做网站推广互联网广告公司
  • 做企业网站用二级域名好吗谷歌seo推广
  • 网站如何做seo排名软文网站发布平台
  • 鄂州做网站的公司seo网络营销外包公司
  • 能免费做公务员题的网站网络营销岗位技能
  • 做外贸都做哪些网站好免费百度推广登陆
  • 蓝色经典通用网站模板网络营销推广方式
  • 网站建设课设心得厦门seo排名优化公司
  • 网站建设公司公司好百度提问登陆入口
  • 东平做网站竞价网站推广
  • 企业网站建设 南通如何建立电商平台
  • 优化防控措施企业网站优化公司
  • 金华做公司网站优化大师下载安装
  • 网站建设公司及网络安全法seo属于什么
  • 陕西省住房和城乡建设委员会网站外贸新手怎样用谷歌找客户
  • 模型外包网站域名信息查询系统
  • 企业电子邮箱怎么注册seo搜索引擎优化课程
  • 建网站的系统软件外包网站
  • 企业建设网站的好处朝阳网站建设公司
  • 免费注册个人邮箱申请seo站长工具
  • hge网站做微端成都最新热门事件
  • 建导航网站关键词优化一年多少钱
  • 建设银行甘肃分行网站今日头条搜索优化怎么做
  • wordpress 速度网站关键词排名优化工具
  • 如何选择电商网站建设seo的工作内容主要包括
  • 接网站做项目赚钱吗百度推广一级代理商名单
  • 北京企业官网建站上海网络推广