• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CardRuntimeException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中javacard.framework.CardRuntimeException的典型用法代码示例。如果您正苦于以下问题:Java CardRuntimeException类的具体用法?Java CardRuntimeException怎么用?Java CardRuntimeException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CardRuntimeException类属于javacard.framework包,在下文中一共展示了CardRuntimeException类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: copyCurve

import javacard.framework.CardRuntimeException; //导入依赖的package包/类
/**
 * Copies this KeyPairs curve parameters to another ECKeyGenerator.
 *
 * @param from   keyPair to copy from
 * @param to     keyPair to copy to
 * @param params parameters to copy
 * @param buffer buffer to use for copying
 * @param offset offset to use in buffer
 * @return sw
 */
public short copyCurve(KeyPair from, KeyPair to, short params, byte[] buffer, short offset) {
    try {
        sw = AppletUtil.keypairCheck(from);
        sw = AppletUtil.keypairCheck(to);

        short param = EC_Consts.PARAMETER_FP;
        while (param <= EC_Consts.PARAMETER_K) {
            short masked = (short) (param & params);
            if (masked != 0) {
                short paramLength = exportParameter(from, EC_Consts.KEY_PUBLIC, masked, buffer, offset);
                setParameter(to, EC_Consts.KEY_BOTH, masked, buffer, offset, paramLength);
            }
            param = (short) (param << 1);
        }
    } catch (CardRuntimeException ce) {
        sw = ce.getReason();
    }
    return sw;
}
 
开发者ID:crocs-muni,项目名称:ECTester,代码行数:30,代码来源:ECKeyGenerator.java


示例2: testKA

import javacard.framework.CardRuntimeException; //导入依赖的package包/类
private short testKA(KeyAgreement ka, KeyPair privatePair, KeyPair publicPair, byte[] pubkeyBuffer, short pubkeyOffset, byte[] outputBuffer, short outputOffset, short corruption) {
    short length = 0;
    try {
        sw = AppletUtil.kaCheck(ka);
        sw = AppletUtil.keypairCheck(privatePair);
        sw = AppletUtil.keypairCheck(publicPair);
        short pubkeyLength = ((ECPublicKey) publicPair.getPublic()).getW(pubkeyBuffer, pubkeyOffset);
        // reached ok
        ka.init(privatePair.getPrivate()); // throws UNITIALIZED KEY when ALG_EC_SVDP_DHC_PLAIN is used
        //ISOException.throwIt((short) 0x666);
        
        pubkeyLength = EC_Consts.corruptParameter(corruption, pubkeyBuffer, pubkeyOffset, pubkeyLength);
        length = ka.generateSecret(pubkeyBuffer, pubkeyOffset, pubkeyLength, outputBuffer, outputOffset);
    } catch (CardRuntimeException ce) {
        sw = ce.getReason();
    }
    return length;
}
 
开发者ID:crocs-muni,项目名称:ECTester,代码行数:19,代码来源:ECKeyTester.java


示例3: testECDSA

import javacard.framework.CardRuntimeException; //导入依赖的package包/类
/**
 * Uses {@code signKey} to sign data from {@code inputBuffer} at {@code inputOffset} with {@code inputOffset}.
 * Then checks for correct signature length.
 * Then tries verifying the data with {@code verifyKey}.
 *
 * @param signKey     key to use for signing
 * @param verifyKey   key to use for verifying the signature
 * @param inputBuffer buffer to sign data from
 * @param inputOffset offset into inputBuffer to sign data from
 * @param inputLength length of data to sign
 * @param sigBuffer   buffer to output signature to
 * @param sigOffset   offset into sigBuffer to output to
 * @return signature length
 */
public short testECDSA(ECPrivateKey signKey, ECPublicKey verifyKey, byte[] inputBuffer, short inputOffset, short inputLength, byte[] sigBuffer, short sigOffset) {
    short length = 0;
    try {
        sw = AppletUtil.signCheck(ecdsaSignature);

        ecdsaSignature.init(signKey, Signature.MODE_SIGN);
        length = ecdsaSignature.sign(inputBuffer, inputOffset, inputLength, sigBuffer, sigOffset);

        ecdsaSignature.init(verifyKey, Signature.MODE_VERIFY);
        boolean correct = ecdsaSignature.verify(inputBuffer, inputOffset, inputLength, sigBuffer, sigOffset, length);
        if (!correct) {
            sw = ECTesterApplet.SW_SIG_VERIFY_FAIL;
        }
    } catch (CardRuntimeException ce) {
        sw = ce.getReason();
    }
    return length;
}
 
开发者ID:crocs-muni,项目名称:ECTester,代码行数:33,代码来源:ECKeyTester.java


示例4: clearPair

import javacard.framework.CardRuntimeException; //导入依赖的package包/类
/**
 *
 * @param keypair
 * @param key
 * @return
 */
public short clearPair(KeyPair keypair, byte key) {
    try {
        sw = AppletUtil.keypairCheck(keypair);
        if ((key & EC_Consts.KEY_PUBLIC) != 0) keypair.getPublic().clearKey();
        if ((key & EC_Consts.KEY_PRIVATE) != 0) keypair.getPrivate().clearKey();
    } catch (CardRuntimeException ce) {
        sw = ce.getReason();
    }
    return sw;
}
 
开发者ID:crocs-muni,项目名称:ECTester,代码行数:17,代码来源:ECKeyGenerator.java


示例5: generatePair

import javacard.framework.CardRuntimeException; //导入依赖的package包/类
/**
 * @param keypair
 * @return
 */
public short generatePair(KeyPair keypair) {
    try {
        sw = AppletUtil.keypairCheck(keypair);
        keypair.genKeyPair();
    } catch (CardRuntimeException ce) {
        sw = ce.getReason();
    }
    return sw;
}
 
开发者ID:crocs-muni,项目名称:ECTester,代码行数:14,代码来源:ECKeyGenerator.java


示例6: allocateECDH

import javacard.framework.CardRuntimeException; //导入依赖的package包/类
public short allocateECDH(byte algorithm) {
    sw = ISO7816.SW_NO_ERROR;
    try {
        ecdhKeyAgreement = KeyAgreement.getInstance(algorithm, false);
    } catch (CardRuntimeException ce) {
        sw = ce.getReason();
    }
    return sw;
}
 
开发者ID:crocs-muni,项目名称:ECTester,代码行数:10,代码来源:ECKeyTester.java


示例7: allocateECDHC

import javacard.framework.CardRuntimeException; //导入依赖的package包/类
public short allocateECDHC(byte algorithm) {
    sw = ISO7816.SW_NO_ERROR;
    try {
        ecdhcKeyAgreement = KeyAgreement.getInstance(algorithm, false);
    } catch (CardRuntimeException ce) {
        sw = ce.getReason();
    }
    return sw;
}
 
开发者ID:crocs-muni,项目名称:ECTester,代码行数:10,代码来源:ECKeyTester.java


示例8: allocateECDSA

import javacard.framework.CardRuntimeException; //导入依赖的package包/类
public short allocateECDSA() {
    sw = ISO7816.SW_NO_ERROR;
    try {
        ecdsaSignature = Signature.getInstance(Signature.ALG_ECDSA_SHA, false);
    } catch (CardRuntimeException ce) {
        sw = ce.getReason();
    }
    return sw;
}
 
开发者ID:crocs-muni,项目名称:ECTester,代码行数:10,代码来源:ECKeyTester.java


示例9: testKA_direct

import javacard.framework.CardRuntimeException; //导入依赖的package包/类
private short testKA_direct(KeyAgreement ka, KeyPair privatePair, byte[] pubkey, short pubkeyOffset, short pubkeyLength, byte[] outpuBuffer, short outputOffset, short corruption) {
    short length = 0;
    try {
        sw = AppletUtil.kaCheck(ka);
        sw = AppletUtil.keypairCheck(privatePair);

        ka.init(privatePair.getPrivate());
        pubkeyLength = EC_Consts.corruptParameter(corruption, pubkey, pubkeyOffset, pubkeyLength);
        length = ka.generateSecret(pubkey, pubkeyOffset, pubkeyLength, outpuBuffer, outputOffset);
    } catch (CardRuntimeException ce)  {
        sw = ce.getReason();
    }
    return length;
}
 
开发者ID:crocs-muni,项目名称:ECTester,代码行数:15,代码来源:ECKeyTester.java


示例10: getSignature

import javacard.framework.CardRuntimeException; //导入依赖的package包/类
private Signature getSignature(byte key_nb, byte alg_id) {
	if (signatures[key_nb] == null) {
		try {
			signatures[key_nb] = Signature.getInstance(alg_id, false);
		} catch (Exception e) {
			ISOException.throwIt(((CardRuntimeException) e).getReason());
		}
	} else if (signatures[key_nb].getAlgorithm() != alg_id)
		ISOException.throwIt(SW_OPERATION_NOT_ALLOWED);
	return signatures[key_nb];
}
 
开发者ID:Toporin,项目名称:SatoChipApplet,代码行数:12,代码来源:CardEdge.java


示例11: setParameter

import javacard.framework.CardRuntimeException; //导入依赖的package包/类
/**
     * @param key
     * @param param
     * @param data
     * @param offset
     * @param length
     * @return
     */
    public short setParameter(KeyPair keypair, byte key, short param, byte[] data, short offset, short length) {
        try {
            sw = AppletUtil.keypairCheck(keypair);

            ECPublicKey ecPublicKey = (ECPublicKey) keypair.getPublic();
            ECPrivateKey ecPrivateKey = (ECPrivateKey) keypair.getPrivate();

            switch (param) {
                case EC_Consts.PARAMETER_FP:
                    if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setFieldFP(data, offset, length);
                    if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setFieldFP(data, offset, length);
                    break;
                case EC_Consts.PARAMETER_F2M:
                    if (length == 4) {
                        short i = Util.makeShort(data[(short) (offset + 2)], data[(short) (offset + 3)]);
                        if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setFieldF2M(i);
                        if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setFieldF2M(i);
                    } else if (length == 8) {
                        short i1 = Util.makeShort(data[(short) (offset + 2)], data[(short) (offset + 3)]);
                        short i2 = Util.makeShort(data[(short) (offset + 4)], data[(short) (offset + 5)]);
                        short i3 = Util.makeShort(data[(short) (offset + 6)], data[(short) (offset + 7)]);
//                        if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setFieldF2M(i1, i2, i3);
//                        if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setFieldF2M(i1, i2, i3);
                        // TODO: fix this, ^^ fails on jcardsim, but is up to spec
                        if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setFieldF2M(i3, i2, i1);
                        if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setFieldF2M(i3, i2, i1);
                    } else {
                        sw = ISO7816.SW_UNKNOWN;
                    }
                    break;
                case EC_Consts.PARAMETER_A:
                    if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setA(data, offset, length);
                    if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setA(data, offset, length);
                    break;
                case EC_Consts.PARAMETER_B:
                    if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setB(data, offset, length);
                    if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setB(data, offset, length);
                    break;
                case EC_Consts.PARAMETER_G:
                    if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setG(data, offset, length);
                    if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setG(data, offset, length);
                    break;
                case EC_Consts.PARAMETER_R:
                    if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setR(data, offset, length);
                    if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setR(data, offset, length);
                    break;
                case EC_Consts.PARAMETER_K:
                    short k = 0;
                    if (length > 2 || length <= 0) {
                        sw = ISO7816.SW_UNKNOWN;
                        break;
                    } else if (length == 2) {
                        k = Util.getShort(data, offset);
                    } else if (length == 1) {
                        k = data[offset];
                    }
                    if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setK(k);
                    if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setK(k);
                    break;
                case EC_Consts.PARAMETER_S:
                    if ((key & EC_Consts.KEY_PRIVATE) != 0) ecPrivateKey.setS(data, offset, length);
                    break;
                case EC_Consts.PARAMETER_W:
                    if ((key & EC_Consts.KEY_PUBLIC) != 0) ecPublicKey.setW(data, offset, length);
                    break;
                default:
                    ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED);
            }
        } catch (CardRuntimeException ce) {
            sw = ce.getReason();
        }
        return sw;
    }
 
开发者ID:crocs-muni,项目名称:ECTester,代码行数:82,代码来源:ECKeyGenerator.java


示例12: exportParameter

import javacard.framework.CardRuntimeException; //导入依赖的package包/类
/**
 * Exports a selected parameter from a given keyPairs key.
 *
 * @param keypair      keypair to export from
 * @param key          key to export from (KEY_PUBLIC || KEY_PRIVATE)
 * @param param        parameter to export (EC_Consts.PARAMETER_* || ...)
 * @param outputBuffer buffer to write to
 * @param outputOffset offset to start writing in buffer
 * @return length of data written
 */
public short exportParameter(KeyPair keypair, byte key, short param, byte[] outputBuffer, short outputOffset) {
    short length = 0;
    try {
        sw = AppletUtil.keypairCheck(keypair);
        ECPublicKey ecPublicKey = (ECPublicKey) keypair.getPublic();
        ECPrivateKey ecPrivateKey = (ECPrivateKey) keypair.getPrivate();

        switch (param) {
            case EC_Consts.PARAMETER_FP:
                if ((key & EC_Consts.KEY_PUBLIC) != 0) length = ecPublicKey.getField(outputBuffer, outputOffset);
                if ((key & EC_Consts.KEY_PRIVATE) != 0) length = ecPrivateKey.getField(outputBuffer, outputOffset);
                break;
            case EC_Consts.PARAMETER_F2M:
                if ((key & EC_Consts.KEY_PUBLIC) != 0) {
                    Util.setShort(outputBuffer, outputOffset, ecPublicKey.getSize());
                    length = 2;
                    length += ecPublicKey.getField(outputBuffer, (short) (outputOffset + 2));
                }
                if ((key & EC_Consts.KEY_PRIVATE) != 0) {
                    Util.setShort(outputBuffer, outputOffset, ecPrivateKey.getSize());
                    length = 2;
                    length += ecPrivateKey.getField(outputBuffer, (short) (outputOffset + 2));
                }
                break;
            case EC_Consts.PARAMETER_A:
                if ((key & EC_Consts.KEY_PUBLIC) != 0) length = ecPublicKey.getA(outputBuffer, outputOffset);
                if ((key & EC_Consts.KEY_PRIVATE) != 0) length = ecPrivateKey.getA(outputBuffer, outputOffset);
                break;
            case EC_Consts.PARAMETER_B:
                if ((key & EC_Consts.KEY_PUBLIC) != 0) length = ecPublicKey.getB(outputBuffer, outputOffset);
                if ((key & EC_Consts.KEY_PRIVATE) != 0) length = ecPrivateKey.getB(outputBuffer, outputOffset);
                break;
            case EC_Consts.PARAMETER_G:
                if ((key & EC_Consts.KEY_PUBLIC) != 0) length = ecPublicKey.getG(outputBuffer, outputOffset);
                if ((key & EC_Consts.KEY_PRIVATE) != 0) length = ecPrivateKey.getG(outputBuffer, outputOffset);
                break;
            case EC_Consts.PARAMETER_R:
                if ((key & EC_Consts.KEY_PUBLIC) != 0) length = ecPublicKey.getR(outputBuffer, outputOffset);
                if ((key & EC_Consts.KEY_PRIVATE) != 0) length = ecPrivateKey.getR(outputBuffer, outputOffset);
                break;
            case EC_Consts.PARAMETER_K:
                length = 2;
                if ((key & EC_Consts.KEY_PUBLIC) != 0)
                    Util.setShort(outputBuffer, outputOffset, ecPublicKey.getK());
                if ((key & EC_Consts.KEY_PRIVATE) != 0)
                    Util.setShort(outputBuffer, outputOffset, ecPrivateKey.getK());
                break;
            case EC_Consts.PARAMETER_W:
                if ((key & EC_Consts.KEY_PUBLIC) != 0) length = ecPublicKey.getW(outputBuffer, outputOffset);
                break;
            case EC_Consts.PARAMETER_S:
                if ((key & EC_Consts.KEY_PRIVATE) != 0) length = ecPrivateKey.getS(outputBuffer, outputOffset);
                break;
            default:
                ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED);
        }
    } catch (CardRuntimeException ce) {
        sw = ce.getReason();
    }
    return length;
}
 
开发者ID:crocs-muni,项目名称:ECTester,代码行数:72,代码来源:ECKeyGenerator.java



注:本文中的javacard.framework.CardRuntimeException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RemoveCacheDirectiveRequestProto类代码示例发布时间:2022-05-23
下一篇:
Java SequenceFileDirValueIterable类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap