本文整理汇总了Java中javacard.security.RandomData类的典型用法代码示例。如果您正苦于以下问题:Java RandomData类的具体用法?Java RandomData怎么用?Java RandomData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RandomData类属于javacard.security包,在下文中一共展示了RandomData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FIDOCCImplementation
import javacard.security.RandomData; //导入依赖的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: FIDOStandalone
import javacard.security.RandomData; //导入依赖的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);
}
示例3: PRNGTest
import javacard.security.RandomData; //导入依赖的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);
}
示例4: authenticateMutualReplayAttack
import javacard.security.RandomData; //导入依赖的package包/类
@Test
public void authenticateMutualReplayAttack() {
byte[] key = DatatypeConverter.parseHexBinary("010203040506070801020304050607080102030405060708");
byte[] myChallenge= new byte [16], globalchallenge = new byte[40], challengeresponse = new byte[40];
byte[] challenge;
Cipher cipherDES = Cipher.getInstance(Cipher.ALG_DES_CBC_NOPAD, false);
DESKey deskey = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_3KEY, false);
deskey.setKey(key, (short) 0);
RandomData randomData = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
randomData.generateData(myChallenge, (short) 0, (short) myChallenge.length);
// select admin key
execute("00 22 81 A4 03 83 01 80");
// get a challenge
ResponseAPDU response = execute("00 87 00 00 14 7C 12 81 10" + DatatypeConverter.printHexBinary(myChallenge) + "00");
if (!Arrays.equals(Arrays.copyOfRange(response.getBytes(), 0, 4), new byte[] {0x7C,0x12,(byte) 0x81,0x10})) {
fail("not a challenge:" + DatatypeConverter.printHexBinary(response.getBytes()));
}
// compute the response
challenge = Arrays.copyOfRange(response.getBytes(), 4, 20);
//solve challenge
//R2
System.arraycopy(challenge, 0, globalchallenge, 0, 16);
//R1
System.arraycopy(myChallenge, 0, globalchallenge, 16, 16);
// keep Z1 random
globalchallenge[(short)39] = (byte) 0x80;
cipherDES.init(deskey, Cipher.MODE_ENCRYPT);
cipherDES.doFinal(globalchallenge, (short) 0, (short)40, challengeresponse, (short) 0);
// send the response
execute("00 87 00 00 2C 7C 2A 82 28" + DatatypeConverter.printHexBinary(challengeresponse), 0x9000);
execute("00 87 00 00 2C 7C 2A 82 28" + DatatypeConverter.printHexBinary(challengeresponse), 0x6985);
}
示例5: CryptonitApplet
import javacard.security.RandomData; //导入依赖的package包/类
protected CryptonitApplet(byte[] bArray, short bOffset, byte bLength) {
mgmt_key = KeyBuilder.buildKey(KeyBuilder.TYPE_DES,
KeyBuilder.LENGTH_DES3_3KEY, false);
((DESKey) mgmt_key).setKey(new byte[]{
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
}, (short) 0);
mgmt_counter = new OwnerPIN(MGMT_MAX_TRIES, (byte) 4);
mgmt_counter.update(new byte[]{0x00, 0x00, 0x00, 0x00}, (short) 0, (byte) 4);
challenge = JCSystem.makeTransientByteArray((short) 8,
JCSystem.CLEAR_ON_DESELECT);
pin = new OwnerPIN(PIN_MAX_TRIES, PIN_MAX_LENGTH);
pin.update(new byte[]{
0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38
}, (short) 0, (byte) 8);
keys = new Key[(byte) 4];
random = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
authenticated = JCSystem.makeTransientBooleanArray((short) 1, JCSystem.CLEAR_ON_DESELECT);
rsa_cipher = Cipher.getInstance(Cipher.ALG_RSA_NOPAD, false);
try {
ec_signature = Signature.getInstance(Signature.ALG_ECDSA_SHA, false);
} catch (Exception e) {
}
FileIndex index = new FileIndex();
io = new IOBuffer(index);
register();
}
示例6: ECTesterApplet
import javacard.security.RandomData; //导入依赖的package包/类
protected ECTesterApplet(byte[] buffer, short offset, byte length) {
if (length > 9) {
/*
short dataOffset = offset;
// shift to privilege offset
dataOffset += (short) (1 + buffer[offset]);
// finally shift to Application specific offset
dataOffset += (short) (1 + buffer[dataOffset]);
// go to proprietary data
dataOffset++;
*/
ramArray = JCSystem.makeTransientByteArray(ARRAY_LENGTH, JCSystem.CLEAR_ON_RESET);
ramArray2 = JCSystem.makeTransientByteArray(ARRAY_LENGTH, JCSystem.CLEAR_ON_RESET);
apduArray = JCSystem.makeTransientByteArray(APDU_MAX_LENGTH, JCSystem.CLEAR_ON_RESET);
dataArray = new byte[ARRAY_LENGTH];
Util.arrayFillNonAtomic(dataArray, (short) 0, ARRAY_LENGTH, (byte) 0);
randomData = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
EC_Consts.randomData = randomData;
keyGenerator = new ECKeyGenerator();
keyTester = new ECKeyTester();
ecdhSW = keyTester.allocateECDH(KeyAgreement.ALG_EC_SVDP_DH);
ecdhcSW = keyTester.allocateECDHC(KeyAgreement.ALG_EC_SVDP_DHC);
//ecdhSW = keyTester.allocateECDH((byte) 3);
//ecdhcSW = keyTester.allocateECDHC((byte) 4);
ecdsaSW = keyTester.allocateECDSA();
}
register();
}
示例7: YkneoOath
import javacard.security.RandomData; //导入依赖的package包/类
public YkneoOath() {
tempBuf = JCSystem.makeTransientByteArray((short) TMP_BUFSIZE, JCSystem.CLEAR_ON_DESELECT);//32
sendBuffer = JCSystem.makeTransientByteArray(BUFSIZE, JCSystem.CLEAR_ON_DESELECT);//2048
propBuf = JCSystem.makeTransientByteArray(PROP_BUF_SIZE, JCSystem.CLEAR_ON_DESELECT);//5
rng = RandomData.getInstance(RandomData.ALG_PSEUDO_RANDOM);
identity = new byte[CHALLENGE_LENGTH];//8
rng.generateData(identity, _0, CHALLENGE_LENGTH);
authObj = new OathObj();
scratchAuth = new OathObj();
}
示例8: YkneoOath
import javacard.security.RandomData; //导入依赖的package包/类
public YkneoOath() {
tempBuf = JCSystem.makeTransientByteArray((short) TMP_BUFSIZE, JCSystem.CLEAR_ON_DESELECT);
sendBuffer = JCSystem.makeTransientByteArray(BUFSIZE, JCSystem.CLEAR_ON_DESELECT);
propBuf = JCSystem.makeTransientByteArray(PROP_BUF_SIZE, JCSystem.CLEAR_ON_DESELECT);
rng = RandomData.getInstance(RandomData.ALG_PSEUDO_RANDOM);
identity = new byte[CHALLENGE_LENGTH];
rng.generateData(identity, _0, CHALLENGE_LENGTH);
authObj = new OathObj();
scratchAuth = new OathObj();
}
示例9: MainApplet
import javacard.security.RandomData; //导入依赖的package包/类
public MainApplet(byte[] buffer, short offset, byte length)
{
random = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
register();
}
示例10: GeneratePrivateKeyECFP
import javacard.security.RandomData; //导入依赖的package包/类
private void GeneratePrivateKeyECFP(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);
short key_size = Util.getShort(buffer, OFFSET_GENKEY_SIZE);
byte options = buffer[OFFSET_GENKEY_OPTIONS];
ECPrivateKey prv_key = (ECPrivateKey) getKey(prv_key_nb, KeyBuilder.TYPE_EC_FP_PRIVATE, key_size);
/* If we're going to overwrite a keyPair's contents, check ACL */
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);
if (randomData == null)
randomData = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
switch (options) {
case OPT_DEFAULT:
// As default params were specified, we have to clear the public key
// if already initialized, otherwise their params would be used.
if (prv_key.isInitialized())
prv_key.clearKey();
break;
case OPT_EC_SECP256k1:
// Bitcoin uses 256-bit keysize!
if (key_size!=256)
ISOException.throwIt(SW_INVALID_PARAMETER);
// Satochip default is secp256k1 (over Fp)
Secp256k1.setCommonCurveParameters(prv_key);
// prv_key.setFieldFP( SECP256K1_P, (short)0, (short)SECP256K1_P.length);
// prv_key.setA( SECP256K1_a, (short)0, (short)SECP256K1_a.length);
// prv_key.setB( SECP256K1_b, (short)0, (short)SECP256K1_b.length);
// prv_key.setG( SECP256K1_G, (short)0, (short)SECP256K1_G.length);
// prv_key.setR( SECP256K1_R, (short)0, (short)SECP256K1_R.length);
// prv_key.setK( SECP256K1_K);
// Set secret value from random
randomData.generateData(recvBuffer,(short)0,(short)(key_size/8));
prv_key.setS(recvBuffer, (short)0, (short)(key_size/8));
Util.arrayFillNonAtomic(recvBuffer, (short)0, (short)(key_size/8), (byte)0);
break;
default:
ISOException.throwIt(SW_INVALID_PARAMETER);
}
}
示例11: GenerateSymmetricKey
import javacard.security.RandomData; //导入依赖的package包/类
/**
* This function generates a symmetric key using the card's on board key generation
* process. The key number, key type, and key size (in bits) are specified
* by arguments P1 and P2 and by provided DATA.
*
* ins: 0x31
* p1: symmetric key number (0x00-0x0F)
* p2: 0x00
* data: [key_type(1) | key_size(2) | key_ACL(6)]
* return: none
*/
private void GenerateSymmetricKey(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 key_nb = buffer[ISO7816.OFFSET_P1];
if ((key_nb < 0) || (key_nb >= MAX_NUM_KEYS))
ISOException.throwIt(SW_INCORRECT_P1);
/* If we're going to overwrite a key contents, check ACL */
if ((keys[key_nb] != null) && keys[key_nb].isInitialized() && !authorizeKeyOp(key_nb,ACL_WRITE))
ISOException.throwIt(SW_UNAUTHORIZED);
/*** Start reading key blob header***/
// blob header= [ key_type(1) | key_size(2) | key_ACL(6)]
// Check entire blob header
if (bytesLeft < 9)
ISOException.throwIt(SW_INVALID_PARAMETER);
short dataOffset= ISO7816.OFFSET_CDATA;
byte key_type = buffer[dataOffset];
dataOffset++; // Skip Key Type
bytesLeft--;
short key_size = Util.getShort(buffer, dataOffset);
dataOffset += (short) 2; // Skip Key Size
bytesLeft -= (short) 2;
Util.arrayCopy(buffer, dataOffset, keyACLs, (short) (key_nb * KEY_ACL_SIZE), KEY_ACL_SIZE);
dataOffset += (short) 6; // Skip ACL
bytesLeft -= (short) 6;
if (randomData == null)
randomData = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
switch (key_type) {
case KeyBuilder.TYPE_AES:
AESKey aes_key = (AESKey) getKey(key_nb, key_type, key_size);
randomData.generateData(recvBuffer,(short)0,(short)(key_size/8));
aes_key.setKey(recvBuffer, (short)0);
break;
case KeyBuilder.TYPE_DES:
DESKey des_key = (DESKey) getKey(key_nb, key_type, key_size);
randomData.generateData(recvBuffer,(short)0,(short)(key_size/8));
des_key.setKey(recvBuffer, (short)0);
break;
default:
ISOException.throwIt(SW_INCORRECT_ALG);
}
// clear recvBuffer
Util.arrayFillNonAtomic(recvBuffer, (short)0, (short)(key_size/8), (byte)0);
}
示例12: initializeKeys
import javacard.security.RandomData; //导入依赖的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);
}
示例13: Gpg
import javacard.security.RandomData; //导入依赖的package包/类
/**
* Only this class's install method should create the applet object.
*/
protected Gpg(byte[] parameters, short offset, byte length) {
pinLength = new byte[3];
pins = new OwnerPIN[3];
pins[PIN_INDEX_PW1] = new OwnerPIN(MAX_TRIES_PIN1, MAX_PIN_LENGTH);
pins[PIN_INDEX_PW1].update(defaultPIN, (short) 0, MIN_PIN1_LENGTH);
pinLength[PIN_INDEX_PW1] = MIN_PIN1_LENGTH;
pins[PIN_INDEX_PW3] = new OwnerPIN(MAX_TRIES_PIN3, MAX_PIN_LENGTH);
pins[PIN_INDEX_PW3].update(defaultPIN, (short) 0, MIN_PIN3_LENGTH);
pinLength[PIN_INDEX_PW3] = MIN_PIN3_LENGTH;
// The resetting code is disabled by default.
pins[PIN_INDEX_RC] = new OwnerPIN(MAX_TRIES_RC, MAX_PIN_LENGTH);
pinLength[PIN_INDEX_RC] = 0;
pinSubmitted = JCSystem.makeTransientBooleanArray((short) 2, JCSystem.CLEAR_ON_DESELECT);
//263bytes
commandChainingBuffer =
JCSystem.makeTransientByteArray((short) (TEMP_PUT_KEY_ACCUMULATOR + RSA_KEY_LENGTH_BYTES),
JCSystem.CLEAR_ON_DESELECT);
privateDO1 = new byte[255];
privateDO2 = new byte[255];
privateDO3 = new byte[255];
privateDO4 = new byte[255];
loginData = new byte[(short) 255];
url = new byte[(short) 255];
name = new byte[(short) 40];
language = new byte[(short) 9];
sex = new byte[(short) 1];
fingerprints = new byte[(short) 60];
caFingerprints = new byte[(short) 60];
generationDates = new byte[(short) 12];
signatureCounter = new byte[(short) 3];
pinValidForMultipleSignatures = (byte) 0;
signatureKey = new KeyPair(KeyPair.ALG_RSA_CRT, (short) 2048);
confidentialityKey = new KeyPair(KeyPair.ALG_RSA_CRT, (short) 2048);
authenticationKey = new KeyPair(KeyPair.ALG_RSA_CRT, (short) 2048);
cipherRSA = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false);
randomData = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
register();
}
示例14: Gpg
import javacard.security.RandomData; //导入依赖的package包/类
/**
* Only this class's install method should create the applet object.
*/
protected Gpg(byte[] parameters, short offset, byte length) {
pinLength = new byte[3];
pins = new OwnerPIN[3];
pins[PIN_INDEX_PW1] = new OwnerPIN(MAX_TRIES_PIN1, MAX_PIN_LENGTH);
pins[PIN_INDEX_PW1].update(defaultPIN, (short) 0, MIN_PIN1_LENGTH);
pinLength[PIN_INDEX_PW1] = MIN_PIN1_LENGTH;
pins[PIN_INDEX_PW3] = new OwnerPIN(MAX_TRIES_PIN3, MAX_PIN_LENGTH);
pins[PIN_INDEX_PW3].update(defaultPIN, (short) 0, MIN_PIN3_LENGTH);
pinLength[PIN_INDEX_PW3] = MIN_PIN3_LENGTH;
// The resetting code is disabled by default.
pins[PIN_INDEX_RC] = new OwnerPIN(MAX_TRIES_RC, MAX_PIN_LENGTH);
pinLength[PIN_INDEX_RC] = 0;
pinSubmitted = JCSystem.makeTransientBooleanArray((short) 2, JCSystem.CLEAR_ON_DESELECT);
commandChainingBuffer =
JCSystem.makeTransientByteArray((short) (TEMP_PUT_KEY_ACCUMULATOR + RSA_KEY_LENGTH_BYTES),
JCSystem.CLEAR_ON_DESELECT);
privateDO1 = new byte[255];
privateDO2 = new byte[255];
privateDO3 = new byte[255];
privateDO4 = new byte[255];
loginData = new byte[(short) 255];
url = new byte[(short) 255];
name = new byte[(short) 40];
language = new byte[(short) 9];
sex = new byte[(short) 1];
fingerprints = new byte[(short) 60];
caFingerprints = new byte[(short) 60];
generationDates = new byte[(short) 12];
signatureCounter = new byte[(short) 3];
pinValidForMultipleSignatures = (byte) 0;
signatureKey = new KeyPair(KeyPair.ALG_RSA_CRT, (short) 2048);
confidentialityKey = new KeyPair(KeyPair.ALG_RSA_CRT, (short) 2048);
authenticationKey = new KeyPair(KeyPair.ALG_RSA_CRT, (short) 2048);
cipherRSA = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false);
randomData = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
register();
}
示例15: STPayP
import javacard.security.RandomData; //导入依赖的package包/类
/**
* Creates Java Card applet object.
*
* @param array
* the byte array containing the AID bytes
* @param offset
* the start of AID bytes in array
* @param length
* the length of the AID bytes in array
*/
private STPayP(byte[] array, short offset, byte length) {
/*** Start allocate memory when applet is instantiated. ***/
this.records = new Records(Constants.MAX_SFI_RECORDS);
this.persistentByteBuffer = new byte[Constants.SIZE_PBB];
this.personalizedPersistentByteBuffer = new byte[Constants.SIZE_PPBB];
this.transientByteBuffer = JCSystem.makeTransientByteArray(Constants.SIZE_TBB, JCSystem.CLEAR_ON_DESELECT);
// NOTE: 'keyEncryption' parameter not used.
this.mkAC = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_2KEY, false);
this.mkIDN = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_2KEY, false);
/*** End allocate memory when applet is instantiated. ***/
/*** Allocate memory when personalized. ***/
this.selectResponse = null;
this.cardLayoutDescriptionPart1 = null;
this.cardLayoutDescriptionPart2 = null;
this.cardLayoutDescriptionPart3 = null;
this.gpState = GPSystem.APPLICATION_SELECTABLE;
/*** Start initialize variables specific to MPP Remote-SE Lite. ***/
this.cardProfile = new CardProfile();
// Build Card Profile.
// NOTE: This is a kludge to retrieve AID. This would not work with real Java Card.
byte aidLength = JCSystem.getAID().getBytes(this.transientByteBuffer, (short) 0);
this.cardProfile.setAid(this.transientByteBuffer, (short) 0, aidLength);
this.cardProfileHash = new byte[32];
// Initialize and seed random.
this.random = RandomData.getInstance(RandomData.ALG_PSEUDO_RANDOM);
byte[] seed = DataUtil.stringToCompressedByteArray(String.valueOf(Calendar.getInstance().getTimeInMillis()));
this.random.setSeed(seed, (short) 0, (short) seed.length);
// Initialize Mobile Key.
this.dataEncryption = new DataEncryption();
if (!this.dataEncryption.initMobileKey()) {
System.out.println("Error: M_Key not initialized.");
}
this.sha256 = MessageDigest.getInstance(MessageDigest.ALG_SHA_256, false);
/*** End initialize variables specific to MPP Remote-SE Lite. ***/
// Register instance AID.
register(array, (short) (offset + (byte) 1), array[offset]);
}