1426 //-------------------------------------------------------------------- 1427 // Clean up. 1428 1429 if (hCryptProv) 1430 ::CryptReleaseContext(hCryptProv, 0); 1431 } 1432 1433 return hKey; // TODO - when finished with this key, call 1434 // CryptDestroyKey(hKey) 1435 } 1436 1437 /* 1438 * Class: sun_security_mscapi_KeyStore 1439 * Method: getKeyLength 1440 * Signature: (J)I 1441 */ 1442 JNIEXPORT jint JNICALL Java_sun_security_mscapi_KeyStore_getKeyLength 1443 (JNIEnv *env, jobject obj, jlong hKey) 1444 { 1445 DWORD dwDataLen = sizeof(DWORD); 1446 BYTE pbData[sizeof(DWORD)]; 1447 DWORD length = 0; 1448 1449 __try 1450 { 1451 // Get key length (in bits) 1452 //TODO - may need to use KP_BLOCKLEN instead? 1453 if (!(::CryptGetKeyParam((HCRYPTKEY) hKey, KP_KEYLEN, (BYTE *)pbData, &dwDataLen, 1454 0))) { 1455 1456 ThrowException(env, KEY_EXCEPTION, GetLastError()); 1457 __leave; 1458 } 1459 length = (DWORD) pbData; 1460 } 1461 __finally 1462 { 1463 // no cleanup required 1464 } 1465 1466 return (jint) length; 1467 } 1468 1469 /* 1470 * Class: sun_security_mscapi_RSACipher 1471 * Method: encryptDecrypt 1472 * Signature: ([BIJZ)[B 1473 */ 1474 JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSACipher_encryptDecrypt 1475 (JNIEnv *env, jclass clazz, jbyteArray jData, jint jDataSize, jlong hKey, 1476 jboolean doEncrypt) 1477 { 1478 jbyteArray result = NULL; 1479 jbyte* pData = NULL; | 1426 //-------------------------------------------------------------------- 1427 // Clean up. 1428 1429 if (hCryptProv) 1430 ::CryptReleaseContext(hCryptProv, 0); 1431 } 1432 1433 return hKey; // TODO - when finished with this key, call 1434 // CryptDestroyKey(hKey) 1435 } 1436 1437 /* 1438 * Class: sun_security_mscapi_KeyStore 1439 * Method: getKeyLength 1440 * Signature: (J)I 1441 */ 1442 JNIEXPORT jint JNICALL Java_sun_security_mscapi_KeyStore_getKeyLength 1443 (JNIEnv *env, jobject obj, jlong hKey) 1444 { 1445 DWORD dwDataLen = sizeof(DWORD); 1446 DWORD length = 0; 1447 1448 __try 1449 { 1450 // Get key length (in bits) 1451 //TODO - may need to use KP_BLOCKLEN instead? 1452 // pbData must be a pointer to a DWORD value with KP_KEYLEN 1453 if (!(::CryptGetKeyParam((HCRYPTKEY) hKey, KP_KEYLEN, (BYTE *)&length, &dwDataLen, 1454 0))) { 1455 1456 ThrowException(env, KEY_EXCEPTION, GetLastError()); 1457 __leave; 1458 } 1459 } 1460 __finally 1461 { 1462 // no cleanup required 1463 } 1464 1465 return (jint) length; 1466 } 1467 1468 /* 1469 * Class: sun_security_mscapi_RSACipher 1470 * Method: encryptDecrypt 1471 * Signature: ([BIJZ)[B 1472 */ 1473 JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSACipher_encryptDecrypt 1474 (JNIEnv *env, jclass clazz, jbyteArray jData, jint jDataSize, jlong hKey, 1475 jboolean doEncrypt) 1476 { 1477 jbyteArray result = NULL; 1478 jbyte* pData = NULL; |