 |
|
SQL Server Tips by Burleson |
MS CryptoAPI based Hash Algorithm Implementations
To initialize MS CryptoAPI we first must acquire a so-called
‘Cryptography Service Provider (CSP)’. A CSP is a software module,
which integrates with the CryptoAPI to provide cryptography
functionality to client applications. This concept is similar to the
approach taken by printer manufacturers in Windows. The manufacturer
of a printer or Microsoft themselves develop a driver which talks
directly to the printer hardware and then presents a standard
interface to Windows and client applications. This allows developers
to develop to the standard printer API’s. This allows Windows
applications to support any printer installed on Windows without the
need for additional application code. Unlike Printer Drivers
however, CSP’s are normally implemented as standard user mode DLLs.
Application code calls the Crypto API functions, which in turn call
the CSP functions. The code used in XP_CRYPTOAPI to initialize a CSP
is as follows:
HCRYPTPROV hProv;
if (CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
{
.
.
Upon successful return of the ‘CryptAcquireContext’ function, we get
a handle to the CSP in the hProv variable. We use the flag
‘CRYPT_VERIFYCONTEXT’ to specify that we do not need access to any
public/private key pairs because we are only interested in hashing
support. This helps speed up this call. We use the ‘CRYPT_SILENT’ to
ensure that the CSP does not display any user interface. This is
especially important in the context of an XP since it will be
running as a service with no one available to respond to any UI,
which might appear.
The above book excerpt is from:
Super SQL
Server Systems
Turbocharge Database Performance with C++ External Procedures
ISBN:
0-9761573-2-2
Joseph Gama, P. J. Naughter
http://www.rampant-books.com/book_2005_2_sql_server_external_procedures.htm |