本文整理汇总了Java中javacard.security.ECKey类的典型用法代码示例。如果您正苦于以下问题:Java ECKey类的具体用法?Java ECKey怎么用?Java ECKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ECKey类属于javacard.security包,在下文中一共展示了ECKey类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FIDOCCImplementation
import javacard.security.ECKey; //导入依赖的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);
}
示例2: checkCurveParameters
import javacard.security.ECKey; //导入依赖的package包/类
public static boolean checkCurveParameters(ECKey eckey, byte[] tmpbuffer, short tmpoffset){
eckey.getA(tmpbuffer, tmpoffset);
if (0!=Util.arrayCompare(tmpbuffer, tmpoffset, SECP256K1, OFFSET_SECP256K1_a, (short)32))
return false;
eckey.getB(tmpbuffer, tmpoffset);
if (0!=Util.arrayCompare(tmpbuffer, tmpoffset, SECP256K1, OFFSET_SECP256K1_b, (short)32))
return false;
eckey.getG(tmpbuffer, tmpoffset);
if (0!=Util.arrayCompare(tmpbuffer, tmpoffset, SECP256K1, OFFSET_SECP256K1_G, (short)65))
return false;
eckey.getR(tmpbuffer, tmpoffset);
if (0!=Util.arrayCompare(tmpbuffer, tmpoffset, SECP256K1, OFFSET_SECP256K1_R, (short)32))
return false;
eckey.getField(tmpbuffer, tmpoffset);
if (0!=Util.arrayCompare(tmpbuffer, tmpoffset, SECP256K1, OFFSET_SECP256K1_P, (short)32))
return false;
if (eckey.getK()!= SECP256K1_K)
return false;
return true;
}
示例3: FIDOStandalone
import javacard.security.ECKey; //导入依赖的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);
}
示例4: setCommonCurveParameters
import javacard.security.ECKey; //导入依赖的package包/类
protected static boolean setCommonCurveParameters(ECKey key) {
try {
key.setA(SECP256R1_A, (short)0, (short)SECP256R1_A.length);
key.setB(SECP256R1_B, (short)0, (short)SECP256R1_B.length);
key.setFieldFP(SECP256R1_FP, (short)0, (short)SECP256R1_FP.length);
key.setG(SECP256R1_G, (short)0, (short)SECP256R1_G.length);
key.setR(SECP256R1_R, (short)0, (short)SECP256R1_R.length);
key.setK(SECP256R1_K);
return true;
}
catch(Exception e) {
return false;
}
}
示例5: PRNGTest
import javacard.security.ECKey; //导入依赖的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);
}
示例6: setCommonCurveParameters
import javacard.security.ECKey; //导入依赖的package包/类
public static void setCommonCurveParameters(ECKey eckey){
eckey.setFieldFP( SECP256K1, OFFSET_SECP256K1_P, (short)32);
eckey.setA( SECP256K1, OFFSET_SECP256K1_a, (short)32);
eckey.setB( SECP256K1, OFFSET_SECP256K1_b, (short)32);
eckey.setR( SECP256K1, OFFSET_SECP256K1_R, (short)32);
eckey.setG( SECP256K1, OFFSET_SECP256K1_G, (short)65);
eckey.setK( SECP256K1_K);
}
示例7: initializeECPoint
import javacard.security.ECKey; //导入依赖的package包/类
public static void initializeECPoint(ECKey ecPoint) {
ecPoint.setFieldFP(CurveConstants.P, BAS, CurveConstants.MODULUS_SIZE);
ecPoint.setA(CurveConstants.A, BAS, CurveConstants.MODULUS_SIZE);
ecPoint.setB(CurveConstants.B, BAS, CurveConstants.MODULUS_SIZE);
ecPoint.setG(CurveConstants.G, BAS, (short) (CurveConstants.MODULUS_SIZE * 2 + 1));
ecPoint.setK(CurveConstants.H);
ecPoint.setR(CurveConstants.N, BAS, CurveConstants.MODULUS_SIZE);
}
示例8: setCommonCurveParameters
import javacard.security.ECKey; //导入依赖的package包/类
protected static boolean setCommonCurveParameters(ECKey key) {
try {
key.setA(SECP256K1_A, (short)0, (short)SECP256K1_A.length);
key.setB(SECP256K1_B, (short)0, (short)SECP256K1_B.length);
key.setFieldFP(SECP256K1_FP, (short)0, (short)SECP256K1_FP.length);
key.setG(SECP256K1_G, (short)0, (short)SECP256K1_G.length);
key.setR(SECP256K1_R, (short)0, (short)SECP256K1_R.length);
key.setK(SECP256K1_K);
return true;
}
catch(Exception e) {
return false;
}
}
示例9: copyDomainParametersFrom
import javacard.security.ECKey; //导入依赖的package包/类
public void copyDomainParametersFrom(ECKey eckey) throws CryptoException {
ISOException.throwIt(Consts.SW_NOTSUPPORTEDYET);
}
示例10: initializeKeys
import javacard.security.ECKey; //导入依赖的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);
}
示例11: initEcParams
import javacard.security.ECKey; //导入依赖的package包/类
/**
* \brief Initialize an EC key with the curve parameters from buf.
*
* \param buf The buffer containing the EC curve parameters. It must be TLV with the following format:
* 81 - prime
* 82 - coefficient A
* 83 - coefficient B
* 84 - base point G
* 85 - order
* 87 - cofactor
*
* \param bOff The offset at where the first entry is located.
*
* \param bLen The remaining length of buf.
*
* \param key The EC key to initialize.
*
* \throw NotFoundException Parts of the data needed to fully initialize
* the key were missing.
*
* \throw InvalidArgumentsException The ASN.1 sequence was malformatted.
*/
private void initEcParams(byte[] buf, short bOff, short bLen, ECKey key) throws NotFoundException, InvalidArgumentsException {
short pos = bOff;
short len;
/* Search for the prime */
pos = UtilTLV.findTag(buf, bOff, bLen, (byte) 0x81);
pos++;
len = UtilTLV.decodeLengthField(buf, pos);
pos += UtilTLV.getLengthFieldLength(len);
key.setFieldFP(buf, pos, len); // "p"
/* Search for coefficient A */
pos = UtilTLV.findTag(buf, bOff, bLen, (byte) 0x82);
pos++;
len = UtilTLV.decodeLengthField(buf, pos);
pos += UtilTLV.getLengthFieldLength(len);
key.setA(buf, pos, len);
/* Search for coefficient B */
pos = UtilTLV.findTag(buf, bOff, bLen, (byte) 0x83);
pos++;
len = UtilTLV.decodeLengthField(buf, pos);
pos += UtilTLV.getLengthFieldLength(len);
key.setB(buf, pos, len);
/* Search for base point G */
pos = UtilTLV.findTag(buf, bOff, bLen, (byte) 0x84);
pos++;
len = UtilTLV.decodeLengthField(buf, pos);
pos += UtilTLV.getLengthFieldLength(len);
key.setG(buf, pos, len); // G(x,y)
/* Search for order */
pos = UtilTLV.findTag(buf, bOff, bLen, (byte) 0x85);
pos++;
len = UtilTLV.decodeLengthField(buf, pos);
pos += UtilTLV.getLengthFieldLength(len);
key.setR(buf, pos, len); // Order of G - "q"
/* Search for cofactor */
pos = UtilTLV.findTag(buf, bOff, bLen, (byte) 0x87);
pos++;
len = UtilTLV.decodeLengthField(buf, pos);
pos += UtilTLV.getLengthFieldLength(len);
if(len == 2) {
key.setK(Util.getShort(buf, pos));
} else if(len == 1) {
key.setK(buf[pos]);
} else {
throw InvalidArgumentsException.getInstance();
}
}