本文整理汇总了Java中javacard.security.RSAPublicKey.setExponent方法的典型用法代码示例。如果您正苦于以下问题:Java RSAPublicKey.setExponent方法的具体用法?Java RSAPublicKey.setExponent怎么用?Java RSAPublicKey.setExponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javacard.security.RSAPublicKey
的用法示例。
在下文中一共展示了RSAPublicKey.setExponent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: GenerateKeyPairRSA
import javacard.security.RSAPublicKey; //导入方法依赖的package包/类
private void GenerateKeyPairRSA(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);
byte pub_key_nb = buffer[ISO7816.OFFSET_P2];
if ((pub_key_nb < 0) || (pub_key_nb >= MAX_NUM_KEYS))
ISOException.throwIt(SW_INCORRECT_P2);
if (pub_key_nb == prv_key_nb)
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
byte alg_id = buffer[OFFSET_GENKEY_ALG];
short key_size = Util.getShort(buffer, OFFSET_GENKEY_SIZE);
byte options = buffer[OFFSET_GENKEY_OPTIONS];
RSAPublicKey pub_key = (RSAPublicKey) getKey(pub_key_nb, KeyBuilder.TYPE_RSA_PUBLIC, key_size);
RSAPrivateKey prv_key = (RSAPrivateKey) getKey(prv_key_nb, alg_id == KeyPair.ALG_RSA ? KeyBuilder.TYPE_RSA_PRIVATE : KeyBuilder.TYPE_RSA_CRT_PRIVATE, key_size);
/* If we're going to overwrite a keyPair's contents, check ACL */
if (pub_key.isInitialized() && !authorizeKeyOp(pub_key_nb,ACL_WRITE))
ISOException.throwIt(SW_UNAUTHORIZED);
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);
/* Store public key ACL */
Util.arrayCopy(buffer, OFFSET_GENKEY_PUB_ACL, keyACLs, (short) (pub_key_nb * KEY_ACL_SIZE), KEY_ACL_SIZE);
switch (options) {
case OPT_DEFAULT:
/* As the default was specified, if public key already * exist we
* have to invalidate it, otherwise its parameters * would be used
* in place of the default ones */
if (pub_key.isInitialized())
pub_key.clearKey();
break;
case OPT_RSA_PUB_EXP:
short exp_length = Util.getShort(buffer, OFFSET_GENKEY_RSA_PUB_EXP_LENGTH);
pub_key.setExponent(buffer, OFFSET_GENKEY_RSA_PUB_EXP_VALUE, exp_length);
break;
default:
ISOException.throwIt(SW_INVALID_PARAMETER);
}
/* TODO: Migrate checks on KeyPair on the top, so we avoid resource
* allocation on error conditions */
/* If no keypair was previously used, ok. If different keypairs were
* used, or for 1 key there is a keypair but the other key not, then
* error If the same keypair object was used previously, check keypair
* size & type */
if ((keyPairs[pub_key_nb] == null) && (keyPairs[prv_key_nb] == null)) {
keyPairs[pub_key_nb] = new KeyPair(pub_key, prv_key);
keyPairs[prv_key_nb] = keyPairs[pub_key_nb];
} else if (keyPairs[pub_key_nb] != keyPairs[prv_key_nb])
ISOException.throwIt(SW_OPERATION_NOT_ALLOWED);
KeyPair kp = keyPairs[pub_key_nb];
if ((kp.getPublic() != pub_key) || (kp.getPrivate() != prv_key))
// This should never happen according with this Applet policies
ISOException.throwIt(SW_INTERNAL_ERROR);
// We Rely on genKeyPair() to make all necessary checks about types
kp.genKeyPair();
}
示例2: initializeKeys
import javacard.security.RSAPublicKey; //导入方法依赖的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);
}