1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| #define RSA512_SIGN_SIZE 64 BOOLEAN MakeKeyRSA512( OUT PUCHAR PublicBuffer, IN ULONG PublicSize, OUT PULONG PublicReal, OUT PUCHAR PrivateBuffer, IN ULONG PrivateSize, OUT PULONG PrivateReal) { NTSTATUS Status; BCRYPT_ALG_HANDLE AlgHandle; BCRYPT_KEY_HANDLE KeyHandle; if (!PublicBuffer || (PublicSize < 91) || !PublicReal || !PrivateBuffer || (PrivateSize < 155) || !PrivateReal) return FALSE; Status = BCryptOpenAlgorithmProvider(&AlgHandle, BCRYPT_RSA_ALGORITHM, NULL, 0); if (!BCRYPT_SUCCESS(Status)) return FALSE; Status = BCryptGenerateKeyPair(AlgHandle, &KeyHandle, RSA512_SIGN_SIZE * 8, 0); if (!BCRYPT_SUCCESS(Status)) { BCryptCloseAlgorithmProvider(AlgHandle, 0); return FALSE; } Status = BCryptFinalizeKeyPair(KeyHandle, 0); if (!BCRYPT_SUCCESS(Status)) { BCryptDestroyKey(KeyHandle); BCryptCloseAlgorithmProvider(AlgHandle, 0); return FALSE; } Status = BCryptExportKey(KeyHandle, NULL, BCRYPT_RSAPUBLIC_BLOB, PublicBuffer, PublicSize, PublicReal, 0); if (!BCRYPT_SUCCESS(Status)) { BCryptDestroyKey(KeyHandle); BCryptCloseAlgorithmProvider(AlgHandle, 0); return FALSE; } Status = BCryptExportKey(KeyHandle, NULL, BCRYPT_RSAPRIVATE_BLOB, PrivateBuffer, PrivateSize, PrivateReal, 0); if (!BCRYPT_SUCCESS(Status)) { BCryptDestroyKey(KeyHandle); BCryptCloseAlgorithmProvider(AlgHandle, 0); return FALSE; } BCryptDestroyKey(KeyHandle); BCryptCloseAlgorithmProvider(AlgHandle, 0); return TRUE; }
|