本文整理汇总了Java中javacard.security.ECPublicKey类的典型用法代码示例。如果您正苦于以下问题:Java ECPublicKey类的具体用法?Java ECPublicKey怎么用?Java ECPublicKey使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ECPublicKey类属于javacard.security包,在下文中一共展示了ECPublicKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newKeyPair
import javacard.security.ECPublicKey; //导入依赖的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;
}
示例2: FIDOCCImplementation
import javacard.security.ECPublicKey; //导入依赖的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);
}
示例3: FIDOStandalone
import javacard.security.ECPublicKey; //导入依赖的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: newKeyPair
import javacard.security.ECPublicKey; //导入依赖的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;
}
示例5: newKeyPair
import javacard.security.ECPublicKey; //导入依赖的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;
}
示例6: newKeyPair
import javacard.security.ECPublicKey; //导入依赖的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;
}
示例7: randomize
import javacard.security.ECPublicKey; //导入依赖的package包/类
/**
* Generates new random point value.
*/
public void randomize(){
if (this.thePointKeyPair == null) {
this.thePointKeyPair = this.theCurve.newKeyPair(this.thePointKeyPair);
this.thePoint = (ECPublicKey) thePointKeyPair.getPublic();
}
else {
this.thePointKeyPair.genKeyPair();
}
}
示例8: PRNGTest
import javacard.security.ECPublicKey; //导入依赖的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);
}
示例9: GenerateExampleBackdooredKeyPair
import javacard.security.ECPublicKey; //导入依赖的package包/类
/**
* Generates intentionally insecure private key to demonstrate behaviour when
* some participants are malicious. Private key bytes are all 0x55 ... 0x55
*/
void GenerateExampleBackdooredKeyPair() {
state.CheckAllowedFunction(StateModel.FNC_QuorumContext_GenerateExampleBackdooredKeyPair);
// If enabled, key is not generated randomly as required per protocol, but fixed to vulnerable value instead
ECPublicKey pub = (ECPublicKey) pair.getPublic();
ECPrivateKey priv = (ECPrivateKey) pair.getPrivate();
// Set "backdoored" (known) private key - all 0x55 ... 0x55
priv.setS(privbytes_backdoored, (short) 0, (short) privbytes_backdoored.length);
((ECPrivateKey) pair.getPrivate()).getS(x_i_Bn, (short) 0);
// Compute and set corresponding public key (to backdoored private one)
cryptoOps.placeholder.ScalarMultiplication(cryptoOps.GenPoint, privbytes_backdoored, cryptoOps.tmp_arr);
pub.setW(cryptoOps.tmp_arr, (short) 0, (short) 65);
}
示例10: sendECPublicKey
import javacard.security.ECPublicKey; //导入依赖的package包/类
private void sendECPublicKey(APDU apdu, ECPublicKey key) {
// T:0x7F,0x49 L:0x43 (67)
// - T:0x86 L:0x41 (65) V:[EC Point 65 bytes]
byte buf[] = new byte[70];
Util.arrayCopy(new byte[]{
(byte) 0x7F, (byte) 0x49, (byte) 0x43, (byte) 0x86, (byte) 0x41
}, (short) 0, buf, (short) 0, (short) 5);
key.getW(buf, (short) 5);
io.sendBuffer(buf, (short) buf.length, apdu);
}
示例11: ecdsa
import javacard.security.ECPublicKey; //导入依赖的package包/类
/**
* @param sign keyPair to use for signing and verification
* @param export whether to export ECDSA signature
* @param inBuffer buffer to read dataLength and data to sign from
* @param inOffset input offset in buffer
* @param outBuffer buffer to write sw to, and export ECDSA signature {@code if(export == EXPORT_TRUE)}
* @param outOffset output offset in buffer
* @return length of data written to the buffer
*/
private short ecdsa(KeyPair sign, byte export, byte[] inBuffer, short inOffset, byte[] outBuffer, short outOffset) {
short length = 0;
short dataLength = Util.getShort(inBuffer, inOffset);
if (dataLength == 0) { //no data to sign
//generate random
dataLength = 64;
randomData.generateData(ramArray, (short) 0, dataLength);
} else {
Util.arrayCopyNonAtomic(inBuffer, (short) (inOffset + 2), ramArray, (short) 0, dataLength);
}
short signatureLength = keyTester.testECDSA((ECPrivateKey) sign.getPrivate(), (ECPublicKey) sign.getPublic(), ramArray, (short) 0, dataLength, ramArray2, (short) 0);
Util.setShort(outBuffer, outOffset, keyTester.getSW());
length += 2;
if (export == EXPORT_TRUE) {
Util.setShort(outBuffer, (short) (outOffset + length), signatureLength);
length += 2;
Util.arrayCopyNonAtomic(ramArray2, (short) 0, outBuffer, (short) (outOffset + length), signatureLength);
length += signatureLength;
}
return length;
}
示例12: generateKeyAndWrap
import javacard.security.ECPublicKey; //导入依赖的package包/类
public short generateKeyAndWrap(byte[] applicationParameter, short applicationParameterOffset, ECPrivateKey generatedPrivateKey, byte[] publicKey, short publicKeyOffset, byte[] keyHandle, short keyHandleOffset) {
// Generate a new pair
keyPair.genKeyPair();
// Copy public key
((ECPublicKey)keyPair.getPublic()).getW(publicKey, publicKeyOffset);
// Wrap keypair and application parameters
((ECPrivateKey)keyPair.getPrivate()).getS(scratch, (short)0);
interleave(applicationParameter, applicationParameterOffset, scratch, (short)0, keyHandle, keyHandleOffset, (short)32);
cipherEncrypt.doFinal(keyHandle, keyHandleOffset, (short)64, keyHandle, keyHandleOffset);
Util.arrayFillNonAtomic(scratch, (short)0, (short)32, (byte)0x00);
return (short)64;
}
示例13: CardApplet
import javacard.security.ECPublicKey; //导入依赖的package包/类
/**
* Allocate memory for the data on the card and initialise the fields
*/
public CardApplet() {
// Get instances of cryptographic operations
agreement = KeyAgreementX.getInstance(KeyAgreementX.ALG_EC_SVDP_DH_PLAIN, false);
// Build keys
privKey = (ECPrivateKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, KEY_LENGTH, false);
pubKey = (ECPublicKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PUBLIC, KEY_LENGTH, false);
blindKeyValue = (ECPrivateKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, KEY_LENGTH, false);
blindKeyPoint = (ECPublicKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PUBLIC, KEY_LENGTH, false);
public_key = new byte[POINT_SIZE];
// Construct key pairs
keyPair = new KeyPair(pubKey, privKey);
blindKeyPair = new KeyPair(blindKeyPoint, blindKeyValue);
// Construct attribute storage
attribute_id = new byte[ATTRIBUTE_COUNT];
Util.arrayFillNonAtomic(attribute_id, _0, ATTRIBUTE_COUNT, (byte) 0x00);
attribute_length = new short[ATTRIBUTE_COUNT];
attribute_signature = new Object[ATTRIBUTE_COUNT];
attribute_value = new Object[ATTRIBUTE_COUNT];
for (short i = 0; i < ATTRIBUTE_COUNT; i++) {
attribute_signature[i] = new byte[POINT_SIZE];
attribute_value[i] = new byte[ATTRIBUTE_SIZE];
}
// Some temporary space
point = JCSystem.makeTransientByteArray((short) (POINT_SIZE*2), JCSystem.CLEAR_ON_RESET);
}
示例14: handleAirgapKeyAgreement
import javacard.security.ECPublicKey; //导入依赖的package包/类
private static void handleAirgapKeyAgreement(APDU apdu) throws ISOException {
short offset = (short)0;
byte[] buffer = apdu.getBuffer();
apdu.setIncomingAndReceive();
checkAirgapPersonalizationAvailable();
if (buffer[ISO7816.OFFSET_P1] == P1_INITIATE_PAIRING) {
if (buffer[ISO7816.OFFSET_LC] != (byte)65) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
pairingDone = false;
Crypto.keyPair.genKeyPair();
Crypto.keyAgreement.init((ECPrivateKey)Crypto.keyPair.getPrivate());
Crypto.keyAgreement.generateSecret(buffer, ISO7816.OFFSET_CDATA, (short)65, scratch256, (short)0);
pairingKey.setKey(scratch256, (short)0);
((ECPublicKey)Crypto.keyPair.getPublic()).getW(buffer, offset);
offset += (short)65;
Crypto.signature.init(attestationPrivate, Signature.MODE_SIGN);
Crypto.signature.sign(buffer, (short)0, (short)65, buffer, offset);
offset += (short)(buffer[(short)(offset + 1)] + 2);
apdu.setOutgoingAndSend((short)0, offset);
}
else
if (buffer[ISO7816.OFFSET_P1] == P1_CONFIRM_PAIRING) {
if (buffer[ISO7816.OFFSET_LC] != (byte)32) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
Crypto.initCipherAES(pairingKey, false);
Crypto.blobEncryptDecryptAES.doFinal(buffer, ISO7816.OFFSET_CDATA, (short)32, scratch256, (short)0);
pairingKey.setKey(scratch256, (short)0);
pairingDone = true;
}
else {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
}
示例15: updatePointObjects
import javacard.security.ECPublicKey; //导入依赖的package包/类
/**
* Properly updates all point values in case of a change of an underlying curve.
* New random point value is generated.
*/
public final void updatePointObjects() {
this.thePointKeyPair = this.theCurve.newKeyPair(this.thePointKeyPair);
this.thePoint = (ECPublicKey) thePointKeyPair.getPublic();
}