Hi all, I use this code for create public key and private key:
public long testPK() throws CardServiceException, CardTerminalException,
ClassNotFoundException, InvalidKeyException
{
System.out.println"\n==============================================================================\nPUPLIC
KEY OPERATIONS TESTS\n");
long time1 = System.currentTimeMillis();// Generated key file
: signature and unwrap key
GPKSignatureUnwrapKeyFile generatedKeyFile = new
GPKSignatureUnwrapKeyFile(ef_3F01,
512, GPKRSAKeyFile.CERTIFIED_KEY); // Authority 1 Public Key File : signature
key
GPKAuthorityKeyFile authority1KeyFile = new GPKAuthorityKeyFile(ef_8002,
512); // Authority 2 Public Key File : signature key
GPKAuthorityKeyFile authority2KeyFile = new GPKAuthorityKeyFile(ef_8005,
512); // Alice's key file (imported) : RSA signature and unwrap key
GPKSignatureUnwrapKeyFile aliceKeyFile = new
GPKSignatureUnwrapKeyFile(ef_8003,
512, GPKRSAKeyFile.UNCERTIFIED_KEY); // Bob's key file (imported) : RSA
signature key
GPKSignatureKeyFile bobKeyFile = new GPKSignatureKeyFile(ef_8004,
512, GPKRSAKeyFile.UNCERTIFIED_KEY); // Chris' key file (on-card) : Signature
key
GPKSignatureKeyFile chrisKeyFile = new GPKSignatureKeyFile(ef_8006,
512, GPKRSAKeyFile.CERTIFIED_KEY);
// CA1 RSA Elements for importation (512 bits)
byte[] ca1Modulus =
HexString.parseHexString("DE60EB370495D9362201A87F6760422490F1D891866DEC1F50E41AA6BBBD1DD8EED6424F229DB250F02DB768C9CE6CE58AF82F83C21BBF25FBA9A68F0AADA991");
byte[] ca1PublicExponent =
HexString.parseHexString("574DA066719895979453DEECD3DF7B04D0C6872569AA39BCE3C4B680D07EA58EE1D258D0682D7E08D20069BAAF4C7A369D04EC798171ED61BE82F15178F3AD59");
// CA2 RSA Elements for importation (1024 bits)
byte[] ca2Modulus =
HexString.parseHexString("B8F1192C2ED36BF672F5C2521B829F2AD1D0757C0F627BB9EEE0C64755F08712FD0A36EB6D68E46298A859C969EC0B969198E2D7D735EC8D48CF6686DFCAF06057A088A573A80597F9F61B3A15CE6E429ACB7DAD0E103ABD877E4620892B6DF9103E33CDF5D47B8179C063407307C65BE9684808FBB2EDAF0485DF8B47603329");
byte[] ca2PublicExponent =
HexString.parseHexString("32DEA60BAF9FF35E3F02D1255D1877D35F35A051BC192609A5ECFC6169DE029DFC471005909C82AC8826696CD14ED467FE569D413D32AD20DC2B7B7D813B4EA407846B6A0B71D735044C88E5AB13C7B29F8EF554407DADADA087E7FE551745A42ACA35A7EBA285923283DDC7B9098A2B97F3BF2E6F34B558CF18CB8EA1FB99E9");
// Alice's elements, certified by CA1 (512 bits)
byte[] aliceModulus =
HexString.parseHexString("8D1F6DAFBFC3DDAAE89CB1D0DDB383B67F8EDAB5D93E402691DC4054AD2B1EF7715A2838CCD46E39B4951E412512140BCAAEE9F1089CBF9F9C6548F1EFBC2919");
byte[] alicePublicExponent =
HexString.parseHexString("2CBB790ADA63CD5537A5FF3D5F4245A38B6E9BF6CFDDCB1288A30B8D286DF48E5AE52277195E58AA8B794C7C71978FBA0147B36B40BDF68A2DE4F9845D0FB38F");
byte[] alicePrivateExponent =
HexString.parseHexString("03CA07692B9595811BF3FE8B5C7FDABCCBE804D57792A9AA9B4C19CF9E7B9C7F811923CB075D4F2CB19DF12966B0E129361F7F5163C38D04E040BFF9046DBBA7");
byte[] aliceSHACertificate =
HexString.parseHexString("71DCF7B57C47F59F5919EB99ED9DC20A5DC226782BBC4084A82DD5627DA2CE08EDE3467553B007D8C9979BC84E3B635501A2D37997BB851B61931A0B5461FDA9");
byte[] aliceMD5Certificate =
HexString.parseHexString("AE8D0F85B2355650DC9B0CA41763D4B347F03ADEFA39AF3069B33E0AC128D22892749857BA35BF3D227102433AF283CA1502E63A3144F8C8A9E4D604A3E7DF64");
// Bob's elements, certified by CA2 (1024 bits)
byte[] bobModulus =
HexString.parseHexString("b5de8bebe71abb243c0f753ac629c8774dde5f6335c95c7fd39fc1b5fbe412a1157e2a6d4abe5e8bf08bf29c8fe3ae3701ed32356a60712eee54e6086a9a3440c7718aea79db3ec3dbc39cd4eb50ada66346ba7c5dd3629e2c7f18adb077174eee622baa10fb3361557eab22d48f76b05dc0ff0bd0279a99045a14958945e58b");
byte[] bobPublicExponent =
HexString.parseHexString("32DEA60BAF9FF35E3F02D1255D1877D35F35A051BC192609A5ECFC6169DE029DFC471005909C82AC8826696CD14ED467FE569D413D32AD20DC2B7B7D813B4EA407846B6A0B71D735044C88E5AB13C7B29F8EF554407DADADA087E7FE551745A42ACA35A7EBA285923283DDC7B9098A2B97F3BF2E6F34B558CF18CB8EA1FB99E9");
byte[] bobPrivateExponent =
HexString.parseHexString("9f30f741cfca6d9d0e946952b100f5edf636140316c5847eb8391f15bcfb92eaa8147d59b9b91b5be3d448bf2ce7b4208ec5cca636d6eab98315578ab034b62e3f8beecc3cd153fe14a04f8bb14f99093f985d8f9753f4732d1f408c963932934ab9c6ce78dcff537a301c110c59e49113dc80feec090f3acd681be1069524a9");
byte[] bobSHACertificate =
HexString.parseHexString("10aadcbe8ef2bf39df40464a14b312acaba5a3455c2dc61f74dac3655acd7df1790b3c059d56d727f0d5c0da36437cfa0139080560454649c5d592de1683718cac075dfd1f30158709109578d97237fb86afdf672b526733006b908a51a066ee8616d2e06596fcf14793fa14f69028a10bb6cdb12905f892e7edf375a99a7dab");
// CRT elements
byte[] bobPrime1 =
HexString.parseHexString("E40E0244A4F9D594C1965200B4FDC90ACDD1CF9D12EEC4A3AE1085A8D3BCCF7A3BCDFEB95E9252DC8A4B5B2B22F51AE25567E1DC7734432B27C5EB13A75FD08B");
byte[] bobPrime2 =
HexString.parseHexString("CF9AA7289B6E9FA927E3C9E114256DF20B9C2B720D2A9CCF29AE4629DAD06A1D3788222B5543BB4C9CDB2D1199BD1BAC65AE586B18A226794E2F3D7D982DAD9B");
byte[] bobCoeff =
HexString.parseHexString("7C100E4AEF2B65B6DE4B42FBB8AA663C820D0012EEA9C714F8C81A269B9D85E1A1E851192D21FE849E221C1F377F1E0621222ACE2AE6767EAD52BFA6DFA41BCA");
byte[] bobExp1 =
HexString.parseHexString("1534B783031DACE8F933CE70658EB45AAD2238254238EB215BB7612E578F2963DE3424ED2FF2AA2637211DC5C43E7F036D92C5A78F67B655EF7C746C7CE7BBD5");
byte[] bobExp2 =
HexString.parseHexString("0A39274AC111773DB25DF58B4116C079946FEA5C5559DC5F53003F4B9C94954DD7E26ED30687BAFE9E17E389A6B33E8F135FBEC13EB01C91CBE64EE4AC74C64F");
// Chris' elements, not certified (768 bits)
byte[] chrisModulus =
HexString.parseHexString("C2069AA61BDFB9592E3C7BA084D4F577CA991BB45D870D68F3A5F707766F011956288869138810D190AE4119C09B7F75A4F34A501C79780E68B5F432B51E5C1FEA58874723EE47EC37A5BA4E2A2665FE2C53763C4487BAD5F1B20A02694FC3B1");
byte[] chrisPublicExponent = HexString.parseHexString("010001");
byte[] chrisPrivateExponent =
HexString.parseHexString("52C56A77EE7034ABDCD3A491C7D8E996DEF10E2695B7A57ADE6630CA183626ABDE5B9045F3351AA7AC270A52A81E2DF30DB5913B5E14187E421F7917A1B5368C7EA442B0D486110F27EF031FBE9968351315D809CD97F4937353DFFAE5B6AC79");
// CRT Elements (each of 384 bits)
byte[] chrisPrime1 =
HexString.parseHexString("D40CA8DF0746944EF677D707234EDB19C5835CA2F9C7DE2A0EC0CD0E7BDB2261A659324EF79D12F0018CA3334245417B");
byte[] chrisPrime2 =
HexString.parseHexString("EA3D9C11419848D557DB155BD146BD216B6C4FB729A10AC1BABD28BDC9B7737598934C5F606C20E61A90CBE411A7B9C3");
byte[] chrisCoeff =
HexString.parseHexString("34B4C05755C948EA232471A9EFBFC24578F32024D87068B15059321F12FC12E33CD75C3F34C1BBAD32DA80CC5F6E3793");
byte[] chrisExp1 =
HexString.parseHexString("97B4C2F0653D2A87DFAF5748850B3A9792866BB531ACBB962D5DE496B327D0CE39FBE0913C77C4FFAEAC166A6AC42F97");
byte[] chrisExp2 =
HexString.parseHexString("2E0CB6A5DDD3665E2ACB73437DBCFE699788CF931EA7FE495FC0D84597666D586D0A683547EB79FC42B4BCA0B5A7D7A9");
// Construct Key objects
RSAPublicKey authority1PublicKey = new RSAPublicKey(ca1PublicExponent.length,
ca1PublicExponent, ca1Modulus, ca1Modulus.length * 8);
RSAPublicKey authority2PublicKey = new RSAPublicKey(ca2PublicExponent.length,
ca2PublicExponent, ca2Modulus, ca2Modulus.length * 8);
RSAPublicKey alicePublicKey = new RSAPublicKey(alicePublicExponent.length,
alicePublicExponent, aliceModulus, aliceModulus.length * 8);
RSAPrivateKey alicePrivateKey = new RSAPrivateKey(aliceModulus,
alicePrivateExponent, 0, 0, aliceModulus.length * 8);
RSAPublicKey bobPublicKey = new RSAPublicKey(bobPublicExponent.length,
bobPublicExponent, bobModulus, bobModulus.length * 8);
RSAPrivateKey bobPrivateKey = new RSAPrivateKey(bobModulus,
bobPrivateExponent,
0, 0, bobModulus.length * 8);
RSACRTKey bobCRTKey = new RSACRTKey(bobPrime1, bobPrime2, bobCoeff,
bobExp1, bobExp2, 0, 0, 512);
RSAPublicKey chrisPublicKey = new RSAPublicKey(chrisPublicExponent.length,
chrisPublicExponent, chrisModulus, chrisModulus.length * 8);
RSAPrivateKey chrisPrivateKey = new RSAPrivateKey(chrisModulus,
chrisPrivateExponent, 0, 0, chrisModulus.length * 8);
RSACRTKey chrisCRTKey = new RSACRTKey(chrisPrime1, chrisPrime2,
chrisCoeff, chrisExp1, chrisExp2, 0, 0, 768);
// Create Secret Key File
System.out.println("\nCreating Secret Key File " + ef_8011);
fus.createSecretKeyFile(ef_8011, 1, null); // Load Secret Key
0
System.out.println("\nLoading Secret Key in " + ef_8011);
fus.import3DESKey(ef_8011, ef_8011_Key,
GPKFileInfo.ADMINISTRATION_SECRET_KEY,
1);// Lock Access conditions
System.out.println("\nLock AC in " + ef_8011);
fss.invalidate(ef_8011); // create 8001 (conditionnal)
System.out.println("\nCreating EF PK RSA " + ef_8001);
if (!fss.exists(ef_8001))
{
kms.createGeneratedPublicKeyFile(generatedKeyFile, null);
} // Generate Key Pair
System.out.println("\nGenerate Key Pair in " + ef_8001);
kgs.generateKeyPair(null, generatedKeyFile, -1, null); // Read
Public Key
System.out.println("\nReading Generated Public Key in EF PK "
+ ef_8001);
RSAPublicKey generatedPublicKey = (RSAPublicKey)
kgs.readPublicKey(generatedKeyFile,
null);
System.out.println(HexString.hexify(generatedPublicKey.modulus().toByteArray()));
// Sign Data
System.out.println("\nSigning data with EF PK " + ef_8001);
byte[] data1ToSign = "I'M SIGNING IN THE RAIN ".getBytes();
byte[] signature1 = scs.signData(generatedKeyFile,
GPKStandardNames.SHA1_RSA,GPKStandardNames.PKCS_PADDING,data1ToSign);
// Verify Signed Data
System.out.println("\nVerify Signed data with EF PK " + ef_8001);
System.out.println("Verified : " + scs.verifySignedData(generatedKeyFile,
GPKStandardNames.SHA1_RSA, GPKStandardNames.PKCS_PADDING, data1ToSign, signature1));
// Unwrap a secret key (PK Open Envelope)
GPKProperties props = GPKObjectRegistry.retrieveProperties(kms.gpkID);
int keySize = props.getMaxSessionKey();
System.out.println("\nUnwrapping a " + keySize + " bytes secret
key with EF PK " + ef_8001);
byte[] fakeCipheredKey = new byte[keySize];
for (int i = 0; i < keySize; i++)
{
fakeCipheredKey[i] = (byte) i;
}
SecretKeySpec plainKey = kms.unwrapSecretKey(generatedKeyFile,
fakeCipheredKey); // create File
kms.createAuthorityKeyFile(authority1KeyFile, ef_8011, authority1PublicKey);
// create File
System.out.println("\nCreating EF PK RSA " + ef_8003);
if (!fss.exists(ef_8003))
{
kms.createImportedPublicKeyFile(aliceKeyFile, ef_8011, alicePublicKey,
alicePrivateKey);
} // Import and Validate Public key
System.out.println("\nImporting and Verifying key in EF PK " +
ef_8003);
byte[] keyInfo ={GPKRSAKeyFile.RSA_FILE_N_TAG, GPKRSAKeyFile.RSA_FILE_V_TAG
};
kis.importAndValidatePublicKey(aliceKeyFile, alicePublicKey, keyInfo,
ArrayUtils.invert(aliceSHACertificate), authority1KeyFile); // Load Private
Key
System.out.println("\nLoading private key in EF PK " + ef_8003);
kis.importPrivateKey(aliceKeyFile, alicePrivateKey, null);
// Sign Data
System.out.println("\nSigning data with EF PK " + ef_8003);
byte[] data4ToSign = "Computers are useless; they can only give
answers".getBytes();
byte[] signature4 = scs.signData(aliceKeyFile, GPKStandardNames.SHA1_RSA,
GPKStandardNames.PKCS_PADDING, data4ToSign); // Verify Signed Data
System.out.println("\nVerify Signed data with EF PK " + ef_8003);
System.out.println("Verified : " + scs.verifySignedData(aliceKeyFile,
GPKStandardNames.SHA1_RSA, GPKStandardNames.PKCS_PADDING, data4ToSign, signature4));
// create CA2 Key file (conditionnal)
System.out.println("\nCreating CA2 PK " + ef_8005);
kms.createAuthorityKeyFile(authority2KeyFile, ef_8011, authority2PublicKey);
// Create Bob's file
System.out.println("\nCreating EF PK RSA " + ef_8004);
if (!fss.exists(ef_8004))
{
kms.createImportedPublicKeyFile(bobKeyFile, ef_8011, bobPublicKey,
bobPrivateKey);
} // Import Bob's public key
System.out.println("\nImporting and Verifying key in EF PK " +
ef_8004);
byte[] keyInfo2 = {GPKRSAKeyFile.RSA_FILE_N_TAG, GPKRSAKeyFile.RSA_FILE_V_TAG
};
kis.importAndValidatePublicKey(bobKeyFile, bobPublicKey, keyInfo2,
ArrayUtils.invert(bobSHACertificate), authority2KeyFile); // Import Bob's
private key
System.out.println("\nImporting private key in EF PK " + ef_8004);
kis.importPrivateKey(bobKeyFile, bobPrivateKey, null); // Sign
Data
System.out.println("\nSigning data with EF PK " + ef_8004);
byte[] data5ToSign = "The future will be better tomorrow".getBytes();
byte[] signature5 = scs.signData(bobKeyFile, GPKStandardNames.SHA1_RSA,
GPKStandardNames.PKCS_PADDING, data5ToSign); // Verify Signed Data
System.out.println("\nVerify Signed data with EF PK " + ef_8004);
System.out.println("Verified : " + scs.verifySignedData(bobKeyFile,
GPKStandardNames.SHA1_RSA, GPKStandardNames.PKCS_PADDING, data5ToSign, signature5));
// Internal Authenticate
System.out.println("\nInternal Authentication with EF PK " + ef_8004);
byte[] randomBytes = new byte[32];
Random generator = new Random();
generator.nextBytes(randomBytes);
byte[] auth = kms.internalAuthenticate(bobKeyFile, GPKStandardNames.SHA1_RSA,
GPKStandardNames.PKCS_PADDING, randomBytes); // Create Card Key File
System.out.println("\nCreating Card key file EF PK " + ef_8006);
kms.createCardKeyFile(chrisKeyFile, ef_8011, chrisPublicKey,
chrisPrivateKey);//
Sign Data
System.out.println("\nSigning data with EF PK " + ef_8006);
byte[] data6ToSign = "Lowery's Law: If it jams - force it. If
it breaks, it needed replacing anyway.".getBytes();
byte[] signature6 = scs.signData(chrisKeyFile, GPKStandardNames.SHA1_RSA,
GPKStandardNames.PKCS_PADDING, data6ToSign); // Verify Signed Data
System.out.println("\nVerify Signed data with EF PK " + ef_8006);
System.out.println("Verified : " + scs.verifySignedData(chrisKeyFile,
GPKStandardNames.SHA1_RSA, GPKStandardNames.PKCS_PADDING, data6ToSign, signature6));
// PK DIR
System.out.println("\nPK Directory");
byte[] list = kms.pkDir(df_8000);
if (list != null)
{
for (int i = 0; i < list.length; i += 3)
{
int fileSize = ArrayUtils.decodeByte(list[i + 1]) *
256 + ArrayUtils.decodeByte(list[i + 2]);
System.out.println("Vediamo un po File with SFI "
+ HexString.hexify(list[i]) + " has body size of " + fileSize + " bytes.");
}
}// Read public elements
System.out.println("\nRead N, V and Cert. public elements from
EF PK " + aliceKeyFile.getPath());
System.out.println(HexString.hexify(fss.readRecord(aliceKeyFile.getPath(),
2)));
System.out.println(HexString.hexify(fss.readRecord(aliceKeyFile.getPath(),
3)));
System.out.println(HexString.hexify(fss.readRecord(aliceKeyFile.getPath(),
4)));
long time2 = System.currentTimeMillis();
long delta = time2 - time1;
return delta;
}
and I have this messagge error:
Unsupported keysize or algorithm parameters
can you help me what is problem wicth cause this messagge and how can resolv
that.
Thanks in advance.
__________________________________________________________________
Partecipa al concorso Tiscali "collegati e vinci",
il primo premio e' un viaggio per 2 persone a Zanzibar!
http://point.tiscali.it/numerounico/
---
> Visit the OpenCard web site at http://www.opencard.org/ for more
> information on OpenCard---binaries, source code, documents.
> This list is being archived at http://www.opencard.org/archive/opencard/
! To unsubscribe from the [EMAIL PROTECTED] mailing list send an email
! to
! [EMAIL PROTECTED]
! containing the word
! unsubscribe
! in the body.