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


Java Cipher.getInstance方法代码示例

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


在下文中一共展示了Cipher.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: KeepassNFC

import javacardx.crypto.Cipher; //导入方法依赖的package包/类
protected KeepassNFC(byte[] bArray, short bOffset, byte bLength)
{
	card_key = new KeyPair(RSA_ALGORITHM, RSA_KEYLENGTH);
	password_key = (AESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_AES, KeyBuilder.LENGTH_AES_128, false);
	transaction_key = (AESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_AES_TRANSIENT_DESELECT, KeyBuilder.LENGTH_AES_128, false);

	card_cipher = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false);
	password_cipher = Cipher.getInstance(Cipher.ALG_AES_BLOCK_128_CBC_NOPAD, false);
	transaction_cipher = Cipher.getInstance(Cipher.ALG_AES_BLOCK_128_CBC_NOPAD, false);

	scratch_area = JCSystem.makeTransientByteArray((short)260, JCSystem.CLEAR_ON_DESELECT);
	aes_key_temporary = JCSystem.makeTransientByteArray((short)260, JCSystem.CLEAR_ON_DESELECT);
	card_cipher_initialised = false;

	/* Generate RSA keypair on install, as if generateCardKey was called. */
	card_key.genKeyPair();

	register();
}
 
开发者ID:nfd,项目名称:smartcard_crypto_applet,代码行数:20,代码来源:KeepassNFC.java

示例2: OpenPGPSecureMessaging

import javacardx.crypto.Cipher; //导入方法依赖的package包/类
/**
 * Construct a new secure messaging wrapper.
 */
public OpenPGPSecureMessaging() {
    ssc = JCSystem.makeTransientByteArray(SSC_SIZE, 
            JCSystem.CLEAR_ON_DESELECT);
    tmp = JCSystem.makeTransientByteArray(TMP_SIZE, 
            JCSystem.CLEAR_ON_DESELECT);
    signer = Signature.getInstance(
            Signature.ALG_DES_MAC8_ISO9797_1_M2_ALG3, false);
    verifier = Signature.getInstance(
            Signature.ALG_DES_MAC8_ISO9797_1_M2_ALG3, false);
    cipher = Cipher.getInstance(
            Cipher.ALG_DES_CBC_ISO9797_M2, false);
    decipher = Cipher.getInstance(
            Cipher.ALG_DES_CBC_ISO9797_M2, false);
    
    keyMAC = (DESKey) KeyBuilder.buildKey(
            KeyBuilder.TYPE_DES_TRANSIENT_DESELECT, 
            KeyBuilder.LENGTH_DES3_2KEY, false);
    keyENC = (DESKey) KeyBuilder.buildKey(
            KeyBuilder.TYPE_DES_TRANSIENT_DESELECT, 
            KeyBuilder.LENGTH_DES3_2KEY, false);
    
    ssc_set = JCSystem.makeTransientBooleanArray((short)1, JCSystem.CLEAR_ON_DESELECT);
    ssc_set[0] = false;
}
 
开发者ID:jderuiter,项目名称:javacard-openpgpcard,代码行数:28,代码来源:OpenPGPSecureMessaging.java

示例3: authenticateGeneralReplayAttack

import javacardx.crypto.Cipher; //导入方法依赖的package包/类
@Test
public void authenticateGeneralReplayAttack() {
    byte[] challenge, challengeresponse = new byte[8];
    byte[] key = DatatypeConverter.parseHexBinary("010203040506070801020304050607080102030405060708");
    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);

    // select admin key
    execute("00 22 81 A4 03 83 01 80");
    // get a challenge
    ResponseAPDU response = execute("00 87 00 00 04 7C 02 81 00 00");
    if (!Arrays.equals(Arrays.copyOfRange(response.getBytes(), 0, 4), new byte[] {0x7C,0x0A,(byte) 0x81,0x08})) {
        fail("not a challenge:" + DatatypeConverter.printHexBinary(response.getBytes()));
    }
    // compute the response
    challenge = Arrays.copyOfRange(response.getBytes(), 4, 12);
    //solve challenge
    cipherDES.init(deskey, Cipher.MODE_ENCRYPT);
    cipherDES.doFinal(challenge, (short) 0, (short)8, challengeresponse, (short) 0);
    // send the response
    execute("00 87 00 00 0C 7C 0A 82 08" + DatatypeConverter.printHexBinary(challengeresponse), 0x9000);
    execute("00 87 00 00 0C 7C 0A 82 08" + DatatypeConverter.printHexBinary(challengeresponse), 0x6985);
}
 
开发者ID:vletoux,项目名称:GidsApplet,代码行数:25,代码来源:PinTests.java

示例4: authenticateGeneral

import javacardx.crypto.Cipher; //导入方法依赖的package包/类
protected void authenticateGeneral(byte[] key, boolean successexpected) {
    byte[] challenge, challengeresponse = new byte[8];
    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);

    // select admin key
    execute("00 22 81 A4 03 83 01 80");
    // get a challenge
    ResponseAPDU response = execute("00 87 00 00 04 7C 02 81 00 00");
    if (!Arrays.equals(Arrays.copyOfRange(response.getBytes(), 0, 4), new byte[] {0x7C,0x0A,(byte) 0x81,0x08})) {
        fail("not a challenge:" + DatatypeConverter.printHexBinary(response.getBytes()));
    }
    // compute the response
    challenge = Arrays.copyOfRange(response.getBytes(), 4, 12);
    //solve challenge
    cipherDES.init(deskey, Cipher.MODE_ENCRYPT);
    cipherDES.doFinal(challenge, (short) 0, (short)8, challengeresponse, (short) 0);
    // send the response
    execute("00 87 00 00 0C 7C 0A 82 08" + DatatypeConverter.printHexBinary(challengeresponse), (successexpected?0x9000: 0x6982));
}
 
开发者ID:vletoux,项目名称:GidsApplet,代码行数:22,代码来源:GidsBaseTestClass.java

示例5: FIDOStandalone

import javacardx.crypto.Cipher; //导入方法依赖的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

示例6: DH

import javacardx.crypto.Cipher; //导入方法依赖的package包/类
public DH() {
    // Creates a RSA private key instance as template for the DH private key
    dhPriv = (RSAPrivateKey) KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PRIVATE_TRANSIENT_RESET, KeyBuilder.LENGTH_RSA_2048, false);

    // Creates an RSA cipher instance
    dhCipher = Cipher.getInstance(Cipher.ALG_RSA_NOPAD, false);

    // Set default G to 2
    G[(short) (maxLength - 1)] = (byte) 0x02;
}
 
开发者ID:ASKGLab,项目名称:DHApplet,代码行数:11,代码来源:DH.java

示例7: DH

import javacardx.crypto.Cipher; //导入方法依赖的package包/类
public DH() {
    // Creates a RSA private key instance as template for the DH private key
    dhPriv = (RSAPrivateKey) KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PRIVATE_TRANSIENT_RESET, KeyBuilder.LENGTH_RSA_2048, false);

    // Creates an RSA cipher instance
    dhCipher = Cipher.getInstance(Cipher.ALG_RSA_NOPAD, false);
}
 
开发者ID:ASKGLab,项目名称:DHApplet,代码行数:8,代码来源:DH.java

示例8: authenticateMutualReplayAttack

import javacardx.crypto.Cipher; //导入方法依赖的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);
}
 
开发者ID:vletoux,项目名称:GidsApplet,代码行数:33,代码来源:PinTests.java

示例9: CryptonitApplet

import javacardx.crypto.Cipher; //导入方法依赖的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();
}
 
开发者ID:mbrossard,项目名称:cryptonit-applet,代码行数:32,代码来源:CryptonitApplet.java

示例10: getCipher

import javacardx.crypto.Cipher; //导入方法依赖的package包/类
private Cipher getCipher(byte key_nb, byte alg_id) {
	if (ciphers[key_nb] == null) {
		ciphers[key_nb] = Cipher.getInstance(alg_id, false);
	} else if (ciphers[key_nb].getAlgorithm() != alg_id)
		ISOException.throwIt(SW_OPERATION_NOT_ALLOWED);
	return ciphers[key_nb];
}
 
开发者ID:Toporin,项目名称:SatoChipApplet,代码行数:8,代码来源:CardEdge.java

示例11: SecureMessaging

import javacardx.crypto.Cipher; //导入方法依赖的package包/类
/**
 * Constructor
 * 
 * @param _tempBuffer a reference for Transient byte array buffer that is used for intermediate operations 
 */
public SecureMessaging(byte[] _tempBuffer) {
	tempBuffer = _tempBuffer;

	mEncryptionKey = (AESKey) KeyBuilder.buildKey(
			KeyBuilder.TYPE_AES_TRANSIENT_DESELECT,
			KeyBuilder.LENGTH_AES_256, false);

	mMackey_1 = (AESKey) KeyBuilder.buildKey(
			KeyBuilder.TYPE_AES_TRANSIENT_DESELECT,
			KeyBuilder.LENGTH_AES_128, false);

	mMackey_2 = (AESKey) KeyBuilder.buildKey(
			KeyBuilder.TYPE_AES_TRANSIENT_DESELECT,
			KeyBuilder.LENGTH_AES_128, false);

	// iv = new byte[(short)0x10];

	mAESCipher = Cipher.getInstance(Cipher.ALG_AES_BLOCK_128_CBC_NOPAD,
			false);

	msgDigest_SHA256 = MessageDigest.getInstance(MessageDigest.ALG_SHA_256,
			false);

	mSignature = Signature.getInstance(Signature.ALG_AES_MAC_128_NOPAD,
			false);

}
 
开发者ID:mobilesec,项目名称:secure-channel-ec-srp-applet,代码行数:33,代码来源:SecureMessaging.java

示例12: FakeEstEID

import javacardx.crypto.Cipher; //导入方法依赖的package包/类
private FakeEstEID() {
	// Use ALG_RSA instead of ALG_RSA_CRT because of K1
	auth = new KeyPair(KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_2048);
	sign = new KeyPair(KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_2048);
	// Not necessary, but be paranoid
	auth.getPrivate().clearKey();
	sign.getPrivate().clearKey();
	auth.getPublic().clearKey();
	sign.getPublic().clearKey();

	// Certificates
	authcert = new byte[0x600];
	Util.arrayFillNonAtomic(authcert, (short) 0, (short) authcert.length, (byte) 0x00);
	signcert = new byte[0x600];
	Util.arrayFillNonAtomic(signcert, (short) 0, (short) signcert.length, (byte) 0x00);

	pd = new PersonalDataFile();
	// Fill all records of pd with 'A'
	for (byte i = 1; i <= 16; i++) {
		byte[] src = pd.rec2field(i);
		Util.arrayFillNonAtomic(src, (short) 0, (short) src.length, (byte) 'A');
	}

	// Operational fields
	runtime_fields = JCSystem.makeTransientShortArray((short) 1, JCSystem.CLEAR_ON_RESET);
	rsa = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false);
	ram = JCSystem.makeTransientByteArray((short) 384, JCSystem.CLEAR_ON_RESET);
}
 
开发者ID:martinpaljak,项目名称:esteid-applets,代码行数:29,代码来源:FakeEstEID.java

示例13: GidsApplet

import javacardx.crypto.Cipher; //导入方法依赖的package包/类
/**
 * \brief Only this class's install method should create the applet object.
 */
protected GidsApplet() {

    // by default the pin manager is in "initialization mode"
    pinManager = new GidsPINManager();

    transmitManager = new TransmitManager();

    currentAlgorithmRef = JCSystem.makeTransientByteArray((short)1, JCSystem.CLEAR_ON_DESELECT);
    currentKey = JCSystem.makeTransientObjectArray((short)1, JCSystem.CLEAR_ON_DESELECT);

    rsaPkcs1Cipher = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false);
    try {
        rsaOaepCipher = Cipher.getInstance(Cipher.ALG_RSA_PKCS1_OAEP, false);
    } catch (CryptoException e) {
        if(e.getReason() == CryptoException.NO_SUCH_ALGORITHM) {
            rsaOaepCipher = null;
        } else {
            throw e;
        }
    }
    rsaRawCipher = Cipher.getInstance(Cipher.ALG_RSA_NOPAD, false);

    byte mechanisms =  (byte) 0xC0;
    fs = new GidsFileSystem(pinManager, transmitManager, (short) 0x3F00,
                            // FCP
                            new byte[]	{
                                (byte)0x62, (byte)0x08,
                                (byte)0x82, (byte)0x01, (byte)0x38, // File descriptor byte.
                                (byte)0x8C, (byte)0x03, (byte)0x03, (byte)0x30, (byte)0x30,// security attribute
                            },
                            // FCI
                            new byte[]	{
                                0x61, 0X12,
                                0x4F, 0x0B, (byte) 0xA0, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x97, (byte) 0x42, (byte) 0x54, (byte) 0x46, (byte) 0x59, 0x02, 0x01, // AID
                                0x73, 0x03,
                                0x40, 0x01, mechanisms, // cryptographic mechanism
                            },
                            // FMD
                            new byte[]	{
                                (byte)0x64, (byte)0x09,
                                (byte)0x5F, (byte)0x2F, (byte) 0x01, (byte) 0x60, // pin usage policy
                                (byte)0x7F, (byte)0x65, 0x02, (byte) 0x80, 0x00
                            }
                           );

    // FCI / FMD / FCP are hard coded
    register();
}
 
开发者ID:vletoux,项目名称:GidsApplet,代码行数:52,代码来源:GidsApplet.java

示例14: authenticateMutual

import javacardx.crypto.Cipher; //导入方法依赖的package包/类
protected void authenticateMutual(byte[] key, boolean successexpected) {
    byte[] myChallenge= new byte [16], globalchallenge = new byte[40], challengeresponse = new byte[40];
    byte[] cardChallenge;
    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);
    new Random().nextBytes(myChallenge);
    // 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
    cardChallenge = Arrays.copyOfRange(response.getBytes(), 4, 20);
    //solve challenge
    //R2
    System.arraycopy(cardChallenge, 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
    String command = "00 87 00 00 2C 7C 2A 82 28" + DatatypeConverter.printHexBinary(challengeresponse);
    
    ResponseAPDU responseAPDU = execute(command, true);
    
    if (!successexpected)
    {
        if(responseAPDU.getSW() != 0x6982) {
            fail("expected: " + Integer.toHexString(0x6982) + " but was: " + Integer.toHexString(response.getSW()));
        }
        return;
    }
    if(responseAPDU.getSW() != 0x9000) {
        fail("expected: " + Integer.toHexString(0x9000) + " but was: " + Integer.toHexString(response.getSW()));
    }
    byte[] cardresponse = responseAPDU.getBytes();
    if (!Arrays.equals(Arrays.copyOfRange(cardresponse, 0, 4), new byte[] {0x7C,0x2A,(byte)0x82,0x28}))
    {
        fail("header verification failed");
    }
    byte[] decryptedCardResponse = new byte[40];
    cipherDES.init(deskey, Cipher.MODE_DECRYPT);
    cipherDES.doFinal(cardresponse, (short) 4, (short)40, decryptedCardResponse, (short) 0);
   
    
    if (!Arrays.equals(Arrays.copyOfRange(decryptedCardResponse, 0, 16), myChallenge)) {
        fail("R1 verification failed");
    }
    
    if (!Arrays.equals(Arrays.copyOfRange(decryptedCardResponse, 16, 32), cardChallenge)) {
        fail("R2 verification failed");
    }
    if (decryptedCardResponse[(short)39] != (byte) 0x80) {
        fail("padding failed");
    }
    
}
 
开发者ID:vletoux,项目名称:GidsApplet,代码行数:63,代码来源:GidsBaseTestClass.java

示例15: initializeKeys

import javacardx.crypto.Cipher; //导入方法依赖的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


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