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


Java KeyPair.getPrivate方法代码示例

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


在下文中一共展示了KeyPair.getPrivate方法的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: initializeKeys

import javacard.security.KeyPair; //导入方法依赖的package包/类
private void initializeKeys() {
	/**
	 * init random data generator
	 */
	mSaltGenerator = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);

	mRsaPublicKekForSquare = (RSAPublicKey) KeyBuilder.buildKey(
			KeyBuilder.TYPE_RSA_PUBLIC, KeyBuilder.LENGTH_RSA_512, false);
	mRsaPublicKeyModPow = (RSAPublicKey) KeyBuilder.buildKey(
			KeyBuilder.TYPE_RSA_PUBLIC, KeyBuilder.LENGTH_RSA_512, false);
	
	mRsaCipherForSquaring = Cipher.getInstance(Cipher.ALG_RSA_NOPAD, false);
	mRsaCipherModPow = Cipher.getInstance(Cipher.ALG_RSA_NOPAD, false);
	
	mRsaPublicKekForSquare.setExponent(SQUARE_EXPONENT, (short) 0x00,
			(short) 0x01);

	// Copy P of used curve to temporary transient memory for faster computation (used several times)
	Util.arrayCopy(CurveConstants.P_forRSAOperation, (short) 0x00, tempBuffer, TEMP_OFFSET_P,
			LENGTH_MODULUS);
	
	/**
	 * set public key modulus
	 */
	mRsaPublicKekForSquare.setModulus(tempBuffer, TEMP_OFFSET_P, (short) LENGTH_RSAOBJECT_MODULUS);
	mRsaPublicKeyModPow.setModulus(tempBuffer, TEMP_OFFSET_P, (short) LENGTH_RSAOBJECT_MODULUS);

	/**
	 * Initialize static values for key agreement
	 */
	mV_Pi = new byte[(short) LENGTH_EC_POINT];
	mREDP = new byte[(short) LENGTH_EC_POINT];
	mSalt = new byte[(short) 0x10];

	/**
	 * Initialize point and agreement scheme for Elliptic curve multiplication
	 */
	mECMultiplHelperPrivatePoint = (ECPrivateKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, KeyBuilder.LENGTH_EC_FP_192, false);
	mECMultiplHelper = KeyAgreementX.getInstance(KeyAgreementX.ALG_EC_SVDP_DH_PLAIN_XY, false);
	
	/**
	 * Initialize EC Keys for Point addition (pub keys from alice and bob)
	 */
	mNxpPointForECAddition = ECPointBuilder.buildECPoint(ECPointBuilder.TYPE_EC_FP_POINT,KeyBuilder.LENGTH_EC_FP_192);

	SRP5Utils.initializeECPoint(mNxpPointForECAddition);
	SRP5Utils.initializeECPoint(mECMultiplHelperPrivatePoint);

	/**
	 * Local public/private key pair
	 */
	mECKeyPairGenerator = new KeyPair(KeyPair.ALG_EC_FP,KeyBuilder.LENGTH_EC_FP_192);
	mLocalECPrivateKey = (ECPrivateKey) mECKeyPairGenerator.getPrivate();
	mLocalECPublicKey = ECPointBuilder.buildECPoint(ECPointBuilder.TYPE_EC_FP_POINT,KeyBuilder.LENGTH_EC_FP_192);

	SRP5Utils.initializeECPoint((ECKey)mECKeyPairGenerator.getPublic());
	SRP5Utils.initializeECPoint(mLocalECPrivateKey);
	SRP5Utils.initializeECPoint(mLocalECPublicKey);
}
 
开发者ID:mobilesec,项目名称:secure-channel-ec-srp-applet,代码行数:60,代码来源:UsmileKeyAgreement.java


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