当前位置: 首页>>代码示例>>Java>>正文


Java KeyPair.getPublic方法代码示例

本文整理汇总了Java中javacard.security.KeyPair.getPublic方法的典型用法代码示例。如果您正苦于以下问题:Java KeyPair.getPublic方法的具体用法?Java KeyPair.getPublic怎么用?Java KeyPair.getPublic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javacard.security.KeyPair的用法示例。


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

示例1: newKeyPair

import javacard.security.KeyPair; //导入方法依赖的package包/类
static public KeyPair newKeyPair() {
	KeyPair kp = new KeyPair(KeyPair.ALG_EC_FP, (short) 256);

	ECPrivateKey ecPrv = (ECPrivateKey) kp.getPrivate();
	ECPublicKey ecPub = (ECPublicKey) kp.getPublic();

	ecPrv.setFieldFP(p, (short) 0, (short) p.length);
	ecPrv.setA(a, (short) 0, (short) a.length);
	ecPrv.setB(b, (short) 0, (short) b.length);
	ecPrv.setG(G, (short) 0, (short) G.length);
	ecPrv.setR(r, (short) 0, (short) r.length);

	ecPub.setFieldFP(p, (short) 0, (short) p.length);
	ecPub.setA(a, (short) 0, (short) a.length);
	ecPub.setB(b, (short) 0, (short) b.length);
	ecPub.setG(G, (short) 0, (short) G.length);
	ecPub.setR(r, (short) 0, (short) r.length);

	return kp;
}
 
开发者ID:Yubico,项目名称:ykneo-curves,代码行数:21,代码来源:SecP256k1.java

示例2: newKeyPair

import javacard.security.KeyPair; //导入方法依赖的package包/类
static public KeyPair newKeyPair() {
	KeyPair key = new KeyPair(KeyPair.ALG_EC_FP, (short) 256);

	ECPrivateKey privKey = (ECPrivateKey) key.getPrivate();
	ECPublicKey pubKey = (ECPublicKey) key.getPublic();

	privKey.setFieldFP(q, (short) 0, (short) q.length);
	privKey.setA(a, (short) 0, (short) a.length);
	privKey.setB(b, (short) 0, (short) b.length);
	privKey.setG(G, (short) 0, (short) G.length);
	privKey.setR(r, (short) 0, (short) r.length);

	pubKey.setFieldFP(q, (short) 0, (short) q.length);
	pubKey.setA(a, (short) 0, (short) a.length);
	pubKey.setB(b, (short) 0, (short) b.length);
	pubKey.setG(G, (short) 0, (short) G.length);
	pubKey.setR(r, (short) 0, (short) r.length);

	return key;
}
 
开发者ID:Yubico,项目名称:ykneo-curves,代码行数:21,代码来源:Frp256v1.java

示例3: newKeyPair

import javacard.security.KeyPair; //导入方法依赖的package包/类
static public KeyPair newKeyPair() {
	KeyPair key = new KeyPair(KeyPair.ALG_EC_FP, (short) 256);

	ECPrivateKey privKey = (ECPrivateKey) key.getPrivate();
	ECPublicKey pubKey = (ECPublicKey) key.getPublic();

	privKey.setFieldFP(p, (short) 0, (short) p.length);
	privKey.setA(a, (short) 0, (short) a.length);
	privKey.setB(b, (short) 0, (short) b.length);
	privKey.setG(G, (short) 0, (short) G.length);
	privKey.setR(r, (short) 0, (short) r.length);

	pubKey.setFieldFP(p, (short) 0, (short) p.length);
	pubKey.setA(a, (short) 0, (short) a.length);
	pubKey.setB(b, (short) 0, (short) b.length);
	pubKey.setG(G, (short) 0, (short) G.length);
	pubKey.setR(r, (short) 0, (short) r.length);

	return key;
}
 
开发者ID:Yubico,项目名称:ykneo-curves,代码行数:21,代码来源:SecP256r1.java

示例4: newKeyPair

import javacard.security.KeyPair; //导入方法依赖的package包/类
static public KeyPair newKeyPair() {
	KeyPair key = new KeyPair(KeyPair.ALG_EC_FP, (short) 320);

	ECPrivateKey privKey = (ECPrivateKey) key.getPrivate();
	ECPublicKey pubKey = (ECPublicKey) key.getPublic();

	privKey.setFieldFP(q, (short) 0, (short) q.length);
	privKey.setA(a, (short) 0, (short) a.length);
	privKey.setB(b, (short) 0, (short) b.length);
	privKey.setG(G, (short) 0, (short) G.length);
	privKey.setR(r, (short) 0, (short) r.length);

	pubKey.setFieldFP(q, (short) 0, (short) q.length);
	pubKey.setA(a, (short) 0, (short) a.length);
	pubKey.setB(b, (short) 0, (short) b.length);
	pubKey.setG(G, (short) 0, (short) G.length);
	pubKey.setR(r, (short) 0, (short) r.length);

	return key;
}
 
开发者ID:Yubico,项目名称:ykneo-curves,代码行数:21,代码来源:BrainpoolP320r1.java

示例5: setParameter

import javacard.security.KeyPair; //导入方法依赖的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

示例6: exportParameter

import javacard.security.KeyPair; //导入方法依赖的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

示例7: GenerateKeyPairRSA

import javacard.security.KeyPair; //导入方法依赖的package包/类
private void GenerateKeyPairRSA(byte[] buffer) {
	byte prv_key_nb = buffer[ISO7816.OFFSET_P1];
	if ((prv_key_nb < 0) || (prv_key_nb >= MAX_NUM_KEYS))
		ISOException.throwIt(SW_INCORRECT_P1);
	byte pub_key_nb = buffer[ISO7816.OFFSET_P2];
	if ((pub_key_nb < 0) || (pub_key_nb >= MAX_NUM_KEYS))
		ISOException.throwIt(SW_INCORRECT_P2);
	if (pub_key_nb == prv_key_nb)
		ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
	byte alg_id = buffer[OFFSET_GENKEY_ALG];
	short key_size = Util.getShort(buffer, OFFSET_GENKEY_SIZE);
	byte options = buffer[OFFSET_GENKEY_OPTIONS];
	RSAPublicKey pub_key = (RSAPublicKey) getKey(pub_key_nb, KeyBuilder.TYPE_RSA_PUBLIC, key_size);
	RSAPrivateKey prv_key = (RSAPrivateKey) getKey(prv_key_nb, alg_id == KeyPair.ALG_RSA ? KeyBuilder.TYPE_RSA_PRIVATE : KeyBuilder.TYPE_RSA_CRT_PRIVATE,	key_size);
	/* If we're going to overwrite a keyPair's contents, check ACL */
	if (pub_key.isInitialized() && !authorizeKeyOp(pub_key_nb,ACL_WRITE))
		ISOException.throwIt(SW_UNAUTHORIZED);
	if (prv_key.isInitialized() && !authorizeKeyOp(prv_key_nb,ACL_WRITE))
		ISOException.throwIt(SW_UNAUTHORIZED);
	/* Store private key ACL */
	Util.arrayCopy(buffer, OFFSET_GENKEY_PRV_ACL, keyACLs, (short) (prv_key_nb * KEY_ACL_SIZE), KEY_ACL_SIZE);
	/* Store public key ACL */
	Util.arrayCopy(buffer, OFFSET_GENKEY_PUB_ACL, keyACLs, (short) (pub_key_nb * KEY_ACL_SIZE), KEY_ACL_SIZE);
	switch (options) {
	case OPT_DEFAULT:
		/* As the default was specified, if public key already * exist we
		 * have to invalidate it, otherwise its parameters * would be used
		 * in place of the default ones */
		if (pub_key.isInitialized())
			pub_key.clearKey();
		break;
	case OPT_RSA_PUB_EXP:
		short exp_length = Util.getShort(buffer, OFFSET_GENKEY_RSA_PUB_EXP_LENGTH);
		pub_key.setExponent(buffer, OFFSET_GENKEY_RSA_PUB_EXP_VALUE, exp_length);
		break;
	default:
		ISOException.throwIt(SW_INVALID_PARAMETER);
	}
	/* TODO: Migrate checks on KeyPair on the top, so we avoid resource
	 * allocation on error conditions  */
	/* If no keypair was previously used, ok. If different keypairs were
	 * used, or for 1 key there is a keypair but the other key not, then
	 * error If the same keypair object was used previously, check keypair
	 * size & type   */
	if ((keyPairs[pub_key_nb] == null) && (keyPairs[prv_key_nb] == null)) {
		keyPairs[pub_key_nb] = new KeyPair(pub_key, prv_key);
		keyPairs[prv_key_nb] = keyPairs[pub_key_nb];
	} else if (keyPairs[pub_key_nb] != keyPairs[prv_key_nb])
		ISOException.throwIt(SW_OPERATION_NOT_ALLOWED);
	KeyPair kp = keyPairs[pub_key_nb];
	if ((kp.getPublic() != pub_key) || (kp.getPrivate() != prv_key))
		// This should never happen according with this Applet policies
		ISOException.throwIt(SW_INTERNAL_ERROR);
	// We Rely on genKeyPair() to make all necessary checks about types
	kp.genKeyPair();
}
 
开发者ID:Toporin,项目名称:SatoChipApplet,代码行数:57,代码来源:CardEdge.java

示例8: process

import javacard.security.KeyPair; //导入方法依赖的package包/类
public void process(APDU apdu) throws ISOException {
	if(selectingApplet()) {
		return;
	}

	short sendlen = 0;
	short recvlen = apdu.setIncomingAndReceive();
	byte[] buf = apdu.getBuffer();
	byte ins = buf[ISO7816.OFFSET_INS];
	
	KeyPair pair = null;
	byte operation = 0;
	if((ins & 0x0f) == 0x01) {
		operation = GENERATE;
	} else if((ins & 0x0f) == 0x02) {
		operation = SIGN;
	} else {
		ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
	}

	switch(ins & 0xf0) {
	case 0x00:
		pair = brainpoolp256r1;
		break;
	case 0x10:
		pair = secp256r1;
		break;
	case 0x20:
		pair = brainpoolp320r1;
		break;
	case 0x30:
		pair = brainpoolp256t1;
		break;
	case 0x40:
		pair = secp256k1;
		break;
	case 0x50:
		pair = gost2001;
		break;
	case 0x60:
		pair = frp256v1;
		break;
	default:
		ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
	}
	if(operation == GENERATE) {
		pair.genKeyPair();
		ECPublicKey pubKey = (ECPublicKey) pair.getPublic();
		sendlen = pubKey.getW(buf, _0);
	} else if(operation == SIGN) {
		signature.init(pair.getPrivate(), Signature.MODE_SIGN);
		sendlen = signature.sign(buf, ISO7816.OFFSET_CDATA, recvlen, buf, _0);
	}
	if(sendlen > 0) {
		apdu.setOutgoingAndSend(_0, sendlen);
	}
}
 
开发者ID:Yubico,项目名称:ykneo-curves,代码行数:58,代码来源:YkneoCurves.java


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