本文整理汇总了Java中javacard.security.RSAPrivateCrtKey类的典型用法代码示例。如果您正苦于以下问题:Java RSAPrivateCrtKey类的具体用法?Java RSAPrivateCrtKey怎么用?Java RSAPrivateCrtKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RSAPrivateCrtKey类属于javacard.security包,在下文中一共展示了RSAPrivateCrtKey类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addKeyPart
import javacard.security.RSAPrivateCrtKey; //导入依赖的package包/类
private short addKeyPart(byte part, byte[] data, short offset, KeyPair key) {
short size = Util.getShort(commandChainingBuffer, TEMP_PUT_KEY_EXPECTED_CHUNK_SIZE);//5
short nextSize = RSA_KEY_HALF_LENGTH_BYTES;//128
switch (part) {
case KEY_PART_E:
((RSAPublicKey) key.getPublic()).setExponent(data, offset, size);
break;
case KEY_PART_PRIME_P:
((RSAPrivateCrtKey) key.getPrivate()).setP(data, offset, size);
break;
case KEY_PART_PRIME_Q:
((RSAPrivateCrtKey) key.getPrivate()).setQ(data, offset, size);
break;
case KEY_PART_PARAM_PQ:
((RSAPrivateCrtKey) key.getPrivate()).setPQ(data, offset, size);
break;
case KEY_PART_PARAM_DP1:
((RSAPrivateCrtKey) key.getPrivate()).setDP1(data, offset, size);
break;
case KEY_PART_PARAM_DQ1:
((RSAPrivateCrtKey) key.getPrivate()).setDQ1(data, offset, size);
nextSize = RSA_KEY_LENGTH_BYTES;//256
break;
case KEY_PART_N:
((RSAPublicKey) key.getPublic()).setModulus(data, offset, RSA_KEY_LENGTH_BYTES);
if (!key.getPrivate().isInitialized() ||
!key.getPublic().isInitialized()) {
ISOException.throwIt(ISO7816.SW_DATA_INVALID);
}
return (short) (offset + RSA_KEY_LENGTH_BYTES);
}
Util.setShort(commandChainingBuffer, TEMP_PUT_KEY_EXPECTED_CHUNK_SIZE, nextSize);//(, 5, 128/256)
return (short) (offset + size);
}
示例2: addKeyPart
import javacard.security.RSAPrivateCrtKey; //导入依赖的package包/类
private short addKeyPart(byte part, byte[] data, short offset, KeyPair key) {
short size = Util.getShort(commandChainingBuffer, TEMP_PUT_KEY_EXPECTED_CHUNK_SIZE);
short nextSize = RSA_KEY_HALF_LENGTH_BYTES;
switch (part) {
case KEY_PART_E:
((RSAPublicKey) key.getPublic()).setExponent(data, offset, size);
break;
case KEY_PART_PRIME_P:
((RSAPrivateCrtKey) key.getPrivate()).setP(data, offset, size);
break;
case KEY_PART_PRIME_Q:
((RSAPrivateCrtKey) key.getPrivate()).setQ(data, offset, size);
break;
case KEY_PART_PARAM_PQ:
((RSAPrivateCrtKey) key.getPrivate()).setPQ(data, offset, size);
break;
case KEY_PART_PARAM_DP1:
((RSAPrivateCrtKey) key.getPrivate()).setDP1(data, offset, size);
break;
case KEY_PART_PARAM_DQ1:
((RSAPrivateCrtKey) key.getPrivate()).setDQ1(data, offset, size);
nextSize = RSA_KEY_LENGTH_BYTES;
break;
case KEY_PART_N:
((RSAPublicKey) key.getPublic()).setModulus(data, offset, RSA_KEY_LENGTH_BYTES);
if (!key.getPrivate().isInitialized() ||
!key.getPublic().isInitialized()) {
ISOException.throwIt(ISO7816.SW_DATA_INVALID);
}
return (short) (offset + RSA_KEY_LENGTH_BYTES);
}
Util.setShort(commandChainingBuffer, TEMP_PUT_KEY_EXPECTED_CHUNK_SIZE, nextSize);
return (short) (offset + size);
}
示例3: decipher
import javacard.security.RSAPrivateCrtKey; //导入依赖的package包/类
/**
* \brief Decipher the data from the apdu using the private key referenced by
* an earlier MANAGE SECURITY ENVIRONMENT apdu.
*
* \param apdu The PERFORM SECURITY OPERATION apdu with P1=80 and P2=86.
*
* \throw ISOException SW_CONDITIONS_NOT_SATISFIED, SW_WRONG_LENGTH and
* SW_WRONG_DATA
*/
private void decipher(APDU apdu) {
short offset_cdata;
short lc;
short decLen = -1;
lc = doChainingOrExtAPDU(apdu);
offset_cdata = 0;
// Padding indicator should be "No further indication".
if(ram_buf[offset_cdata] != (byte) 0x00) {
ISOException.throwIt(ISO7816.SW_WRONG_DATA);
}
switch(currentAlgorithmRef[0]) {
case ALG_RSA_PAD_PKCS1:
// Get the key - it must be an RSA private key,
// checks have been done in MANAGE SECURITY ENVIRONMENT.
RSAPrivateCrtKey theKey = (RSAPrivateCrtKey) keys[currentPrivateKeyRef[0]];
// Check the length of the cipher.
// Note: The first byte of the data field is the padding indicator
// and therefor not part of the ciphertext.
if((short)(lc-1) != (short)(theKey.getSize() / 8)) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
rsaPkcs1Cipher.init(theKey, Cipher.MODE_DECRYPT);
try {
decLen = rsaPkcs1Cipher.doFinal(ram_buf, (short)(offset_cdata+1), (short)(lc-1),
apdu.getBuffer(), (short) 0);
} catch(CryptoException e) {
ISOException.throwIt(ISO7816.SW_WRONG_DATA);
}
// We have to send at most 256 bytes. A short APDU can handle that - only one send operation neccessary.
apdu.setOutgoingAndSend((short)0, decLen);
break;
default:
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED);
}
}