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


Java KeyPair类代码示例

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


KeyPair类属于javacard.security包,在下文中一共展示了KeyPair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: FIDOCCImplementation

import javacard.security.KeyPair; //导入依赖的package包/类
public FIDOCCImplementation() {
	
	random = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
	
    scratch = JCSystem.makeTransientByteArray((short)128, JCSystem.CLEAR_ON_DESELECT);
    //seed = new byte[64];
    
    keyPair = new KeyPair(
        (ECPublicKey)KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PUBLIC, KeyBuilder.LENGTH_EC_FP_256, false),
        (ECPrivateKey)KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, KeyBuilder.LENGTH_EC_FP_256, false));
    Secp256r1.setCommonCurveParameters((ECKey)keyPair.getPrivate());
    Secp256r1.setCommonCurveParameters((ECKey)keyPair.getPublic());
            
    // Initialize the unique seed for DRNG function 
    //random.generateData(seed, (short)0, (short)64);
    
    // Initialize the unique seed for DRNG function       
    drngSeed1 = (AESKey)KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC, KeyBuilder.LENGTH_AES_256, false);
    drngSeed2 = (AESKey)KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC, KeyBuilder.LENGTH_AES_256, false);
    random.generateData(scratch, (short)0, (short)32);
    drngSeed1.setKey(scratch, (short)0);
    random.generateData(scratch, (short)0, (short)32);
    drngSeed2.setKey(scratch, (short)0);
 
    sha256 = MessageDigest.getInstance(MessageDigest.ALG_SHA_256, false);
            
    // Initialize the unique keys for MAC function
    macKey1 = (AESKey)KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC, KeyBuilder.LENGTH_AES_128, false);
    macKey2 = (AESKey)KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC, KeyBuilder.LENGTH_AES_128, false);
    random.generateData(scratch, (short)0, (short)16);
    macKey1.setKey(scratch, (short)0);
    random.generateData(scratch, (short)0, (short)16);
    macKey2.setKey(scratch, (short)0);
    
    // Initialize ecMultiplier 
    ecMultiplyHelper = KeyAgreementX.getInstance(KeyAgreementX.ALG_EC_SVDP_DH_PLAIN_XY, false);
}
 
开发者ID:tsenger,项目名称:CCU2F,代码行数:38,代码来源:FIDOCCImplementation.java

示例3: corruptCurve

import javacard.security.KeyPair; //导入依赖的package包/类
/**
 * @param keypair
 * @param key
 * @param corruptParams
 * @param corruption
 * @param buffer
 * @param offset
 * @return
 */
public short corruptCurve(KeyPair keypair, byte key, short corruptParams, byte corruption, byte[] buffer, short offset) {
    sw = ISO7816.SW_NO_ERROR;
    if (corruptParams == EC_Consts.PARAMETERS_NONE) {
        return sw;
    }

    //go through param bit by bit, and invalidate all selected params
    short paramMask = EC_Consts.PARAMETER_FP;
    while (paramMask <= EC_Consts.PARAMETER_S) {
        short masked = (short) (paramMask & corruptParams);
        if (masked != 0) {
            short length = exportParameter(keypair, key, masked, buffer, offset);
            length = EC_Consts.corruptParameter(corruption, buffer, offset, length);
            sw = setParameter(keypair, key, masked, buffer, offset, length);
            if (sw != ISO7816.SW_NO_ERROR) break;
        }
        paramMask = (short) (paramMask << 1);
    }
    return sw;
}
 
开发者ID:crocs-muni,项目名称:ECTester,代码行数:30,代码来源:ECKeyGenerator.java

示例4: setExternalCurve

import javacard.security.KeyPair; //导入依赖的package包/类
/**
 * @param keypair
 * @param key
 * @param params
 * @param inBuffer
 * @param inOffset
 * @return
 */
public short setExternalCurve(KeyPair keypair, byte key, short params, byte[] inBuffer, short inOffset) {
    sw = ISO7816.SW_NO_ERROR;
    if (params == EC_Consts.PARAMETERS_NONE) {
        return sw;
    }

    short paramMask = EC_Consts.PARAMETER_FP;
    while (paramMask <= EC_Consts.PARAMETER_S) {
        short masked = (short) (paramMask & params);
        if (masked != 0) {
            short paramLength = Util.getShort(inBuffer, inOffset);
            inOffset += 2;
            sw = setParameter(keypair, key, masked, inBuffer, inOffset, paramLength);
            inOffset += paramLength;
            if (sw != ISO7816.SW_NO_ERROR) break;
        }
        paramMask = (short) (paramMask << 1);
    }
    return sw;
}
 
开发者ID:crocs-muni,项目名称:ECTester,代码行数:29,代码来源:ECKeyGenerator.java

示例5: exportParameters

import javacard.security.KeyPair; //导入依赖的package包/类
/**
 * Exports selected parameters from a given keyPairs key.
 * Raw parameter data is always prepended by its length as a
 * short value. The order of parameters is the usual one from
 * EC_Consts: field,a,b,g,r,k,w,s.
 *
 * @param keypair keyPair to export from
 * @param key     key to export from (KEY_PUBLIC || KEY_PRIVATE)
 * @param params  params to export (EC_Consts.PARAMETER_* | ...)
 * @param buffer  buffer to export to
 * @param offset  offset to start writing in buffer
 * @return length of data written
 */
public short exportParameters(KeyPair keypair, byte key, short params, byte[] buffer, short offset) {
    sw = ISO7816.SW_NO_ERROR;
    if (params == EC_Consts.PARAMETERS_NONE) {
        return sw;
    }

    short length = 0;
    short paramMask = EC_Consts.PARAMETER_FP;
    while (paramMask <= EC_Consts.PARAMETER_S) {
        short masked = (short) (paramMask & params);
        if (masked != 0) {
            short len = exportParameter(keypair, key, masked, buffer, (short) (offset + 2));
            if (len == 0) {
                paramMask = (short) (paramMask << 1);
                continue;
            }
            Util.setShort(buffer, offset, len);
            offset += len + 2;
            length += len + 2;
        }
        paramMask = (short) (paramMask << 1);
    }
    return length;
}
 
开发者ID:crocs-muni,项目名称:ECTester,代码行数:38,代码来源:ECKeyGenerator.java

示例6: copyCurve

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

示例7: set

import javacard.security.KeyPair; //导入依赖的package包/类
/**
 * @param keyPair   KeyPair to set params on
 * @param curve     curve to set (EC_Consts.CURVE_*)
 * @param params    parameters to set (EC_Consts.PARAMETER_* | ...)
 * @param inBuffer  buffer to read params from
 * @param inOffset  input offset in buffer
 * @param outBuffer buffer to write sw to
 * @param outOffset output offset in buffer
 * @return length of data written to the buffer
 */
private short set(KeyPair keyPair, byte curve, short params, byte[] inBuffer, short inOffset, byte[] outBuffer, short outOffset) {
    short sw = ISO7816.SW_NO_ERROR;

    switch (curve) {
        case EC_Consts.CURVE_default:
            //default, dont set anything
            break;
        case EC_Consts.CURVE_external:
            //external
            sw = keyGenerator.setExternalCurve(keyPair, params, inBuffer, inOffset);
            break;
        default:
            //custom
            sw = keyGenerator.setCurve(keyPair, curve, params, ramArray, (short) 0);
            break;
    }

    Util.setShort(outBuffer, outOffset, sw);
    return 2;
}
 
开发者ID:crocs-muni,项目名称:ECTester,代码行数:31,代码来源:ECTesterApplet.java

示例8: export

import javacard.security.KeyPair; //导入依赖的package包/类
/**
 * @param keyPair   KeyPair to export from
 * @param key       which key to export from (EC_Consts.KEY_PUBLIC | EC_Consts.KEY_PRIVATE)
 * @param params    which params to export (EC_Consts.PARAMETER_* | ...)
 * @param outBuffer buffer to export params to
 * @param swOffset  offset to output sw to buffer
 * @param outOffset output offset in buffer
 * @return length of data written to the buffer
 */
private short export(KeyPair keyPair, byte key, short params, byte[] outBuffer, short swOffset, short outOffset) {
    short length = 0;

    short sw = ISO7816.SW_NO_ERROR;
    if ((key & EC_Consts.KEY_PUBLIC) != 0) {
        //export params from public
        length += keyGenerator.exportParameters(keyPair, EC_Consts.KEY_PUBLIC, params, outBuffer, outOffset);
        sw = keyGenerator.getSW();
    }
    //TODO unify this, now that param key == the passed on param.
    if ((key & EC_Consts.KEY_PRIVATE) != 0 && sw == ISO7816.SW_NO_ERROR) {
        //export params from private
        length += keyGenerator.exportParameters(keyPair, EC_Consts.KEY_PRIVATE, params, outBuffer, (short) (outOffset + length));
        sw = keyGenerator.getSW();
    }
    Util.setShort(outBuffer, swOffset, sw);

    return length;
}
 
开发者ID:crocs-muni,项目名称:ECTester,代码行数:29,代码来源:ECTesterApplet.java

示例9: GenerateKeyPair

import javacard.security.KeyPair; //导入依赖的package包/类
/** 
 * This function generates a key pair using the card's on board key generation
 * process. The key number (or numbers if a key pair is being generated), algorithm
 * type, and algorithm parameters are specified by arguments P1 and P2 and by
 * provided DATA.
 * 
 * ins: 0x30
 * p1: private key number (0x00-0x0F)
 * p2: public key number (0x00-0x0F)
 * data: [Key Generation Parameters] 
 * return: none
 */
private void GenerateKeyPair(APDU apdu, byte[] buffer) {
	short bytesLeft = Util.makeShort((byte) 0x00, buffer[ISO7816.OFFSET_LC]);
	if (bytesLeft != apdu.setIncomingAndReceive())
		ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
	byte alg_id = buffer[OFFSET_GENKEY_ALG];
	switch (alg_id) {
		case KeyPair.ALG_RSA:
		case KeyPair.ALG_RSA_CRT:
			GenerateKeyPairRSA(buffer);
			break;
		case KeyPair.ALG_EC_FP:
			//GenerateKeyPairECFP(buffer);
			GeneratePrivateKeyECFP(buffer);
			break;
		default:
			ISOException.throwIt(SW_INCORRECT_ALG);
	}
}
 
开发者ID:Toporin,项目名称:SatoChipApplet,代码行数:31,代码来源:CardEdge.java

示例10: FIDOStandalone

import javacard.security.KeyPair; //导入依赖的package包/类
public FIDOStandalone() {
    scratch = JCSystem.makeTransientByteArray((short)64, JCSystem.CLEAR_ON_DESELECT);
    keyPair = new KeyPair(
        (ECPublicKey)KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PUBLIC, KeyBuilder.LENGTH_EC_FP_256, false),
        (ECPrivateKey)KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, KeyBuilder.LENGTH_EC_FP_256, false));
    Secp256r1.setCommonCurveParameters((ECKey)keyPair.getPrivate());
    Secp256r1.setCommonCurveParameters((ECKey)keyPair.getPublic());
    random = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
    // Initialize the unique wrapping key
    chipKey = (AESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_AES, KeyBuilder.LENGTH_AES_256, false);
    random.generateData(scratch, (short)0, (short)32);
    chipKey.setKey(scratch, (short)0);
    cipherEncrypt = Cipher.getInstance(Cipher.ALG_AES_BLOCK_128_CBC_NOPAD, false);
    cipherEncrypt.init(chipKey, Cipher.MODE_ENCRYPT, IV_ZERO_AES, (short)0, (short)IV_ZERO_AES.length);
    cipherDecrypt = Cipher.getInstance(Cipher.ALG_AES_BLOCK_128_CBC_NOPAD, false);
    cipherDecrypt.init(chipKey, Cipher.MODE_DECRYPT, IV_ZERO_AES, (short)0, (short)IV_ZERO_AES.length);
}
 
开发者ID:LedgerHQ,项目名称:ledger-u2f-javacard,代码行数:18,代码来源:FIDOStandalone.java

示例11: 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

示例12: 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

示例13: 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

示例14: PRNGTest

import javacard.security.KeyPair; //导入依赖的package包/类
private PRNGTest() {
	random = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);

	drngAESKey = (AESKey) KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC,
			KeyBuilder.LENGTH_AES_128, false);

	tmp = JCSystem.makeTransientByteArray((short) 40,
			JCSystem.CLEAR_ON_DESELECT);

	random.generateData(tmp, (short) 0, (short) 16);
	drngAESKey.setKey(tmp, (short) 0);

	scratch = JCSystem.makeTransientByteArray((short) 32,
			JCSystem.CLEAR_ON_DESELECT);

	keyPair = new KeyPair((ECPublicKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PUBLIC, KeyBuilder.LENGTH_EC_FP_256,false), 
			(ECPrivateKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, KeyBuilder.LENGTH_EC_FP_256, false));
	Secp256r1.setCommonCurveParameters((ECKey) keyPair.getPrivate());
	Secp256r1.setCommonCurveParameters((ECKey) keyPair.getPublic());

	

	// Initialize the unique key for DRNG function (AES CMAC)
	drngKey1 = (AESKey) KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC,
			KeyBuilder.LENGTH_AES_128, false);
	drngKey2 = (AESKey) KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC,
			KeyBuilder.LENGTH_AES_128, false);
	random.generateData(scratch, (short) 0, (short) 32);
	drngKey1.setKey(scratch, (short) 0);
	drngKey2.setKey(scratch, (short) 16);

	drng1 = SignatureX.getInstance(SignatureX.ALG_AES_CMAC16, false);
	drng1.init(drngKey1, Signature.MODE_SIGN);
	drng2 = SignatureX.getInstance(SignatureX.ALG_AES_CMAC16, false);
	drng2.init(drngKey2, Signature.MODE_SIGN);

	// Initialize the unique key for MAC function (AES CMAC)
	macKey = (AESKey) KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC,
			KeyBuilder.LENGTH_AES_128, false);
	random.generateData(scratch, (short) 0, (short) 16);
	macKey.setKey(scratch, (short) 0);

	cmacSign = SignatureX.getInstance(SignatureX.ALG_AES_CMAC16, false);
	cmacSign.init(macKey, Signature.MODE_SIGN);

	cmacVerify = SignatureX.getInstance(SignatureX.ALG_AES_CMAC16, false);
	cmacVerify.init(macKey, Signature.MODE_VERIFY);

	// Initialize ecMultiplier
	ecMultiplyHelper = KeyAgreementX.getInstance(KeyAgreementX.ALG_EC_SVDP_DH_PLAIN_XY, false);
}
 
开发者ID:tsenger,项目名称:CCU2F,代码行数:52,代码来源:PRNGTest.java

示例15: getDescription

import javacard.security.KeyPair; //导入依赖的package包/类
@Override
public String getDescription() {
    String field = keyClass == KeyPair.ALG_EC_FP ? "ALG_EC_FP" : "ALG_EC_F2M";
    String key;
    if (keyPair == ECTesterApplet.KEYPAIR_BOTH) {
        key = "both keypairs";
    } else {
        key = ((keyPair == ECTesterApplet.KEYPAIR_LOCAL) ? "local" : "remote") + " keypair";
    }
    return String.format("Allocated %s %db %s", key, keyLength, field);
}
 
开发者ID:crocs-muni,项目名称:ECTester,代码行数:12,代码来源:Response.java


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