找到一个现成的:<br><br>unit wincrypt;<br><br>{$ALIGN ON}<br><br>{$IFNDEF VER90}<br> {$WEAKPACKAGEUNIT}<br>{$ENDIF}<br>interface<br><br>uses<br> Windows;<br><br>const<br> CryptDll = 'advapi32.dll';<br><br> {---------------------------------------------------------------------------<br><br> Microsoft Windows<br> Copyright (C) Microsoft Corporation, 1992 - 1996.<br><br> File: wincrypt.h<br> Contents: Cryptographic API Prototypes and Definitions<br> ----------------------------------------------------------------------------}<br><br> {Algorithm IDs and Flags }<br><br> {ALG_ID crackers }<br>function GET_ALG_CLASS(x :integer) :integer;<br>function GET_ALG_TYPE(x :integer) :integer;<br>function GET_ALG_SID(x :integer) :integer;<br><br>{Algorithm classes }<br>const<br> ALG_CLASS_ANY = 0;<br> ALG_CLASS_SIGNATURE = (1 shl 13);<br> ALG_CLASS_MSG_ENCRYPT = (2 shl 13);<br> ALG_CLASS_DATA_ENCRYPT = (3 shl 13);<br> ALG_CLASS_HASH = (4 shl 13);<br> ALG_CLASS_KEY_EXCHANGE = (5 shl 13);<br> {Algorithm types }<br> ALG_TYPE_ANY = 0;<br> ALG_TYPE_DSS = (1 shl 9);<br> ALG_TYPE_RSA = (2 shl 9);<br> ALG_TYPE_BLOCK = (3 shl 9);<br> ALG_TYPE_STREAM = (4 shl 9);<br> {Generic sub-ids }<br> ALG_SID_ANY = 0;<br> {Some RSA sub-ids }<br> ALG_SID_RSA_ANY = 0;<br> ALG_SID_RSA_PKCS = 1;<br> ALG_SID_RSA_MSATWORK = 2;<br> ALG_SID_RSA_ENTRUST = 3;<br> ALG_SID_RSA_PGP = 4;<br> {Some DSS sub-ids}<br> ALG_SID_DSS_ANY = 0;<br> ALG_SID_DSS_PKCS = 1;<br> ALG_SID_DSS_DMS = 2;<br> {Block cipher sub ids DES sub_ids }<br> ALG_SID_DES = 1;<br> ALG_SID_3DES = 3;<br> ALG_SID_DESX = 4;<br> ALG_SID_IDEA = 5;<br> ALG_SID_CAST = 6;<br> ALG_SID_SAFERSK64 = 7;<br> ALD_SID_SAFERSK128 = 8;<br> {KP_MODE }<br> CRYPT_MODE_CBCI = 6; {ANSI CBC Interleaved}<br> CRYPT_MODE_CFBP = 7; {ANSI CFB Pipelined}<br> CRYPT_MODE_OFBP = 8; {ANSI OFB Pipelined}<br> CRYPT_MODE_CBCOFM = 9; {ANSI CBC + OF Masking}<br> CRYPT_MODE_CBCOFMI = 10; {ANSI CBC + OFM Interleaved}<br> {RC2 sub-ids }<br> ALG_SID_RC2 = 2;<br> {Stream cipher sub-ids }<br> ALG_SID_RC4 = 1;<br> ALG_SID_SEAL = 2;<br> {Hash sub ids }<br> ALG_SID_MD2 = 1;<br> ALG_SID_MD4 = 2;<br> ALG_SID_MD5 = 3;<br> ALG_SID_SHA = 4;<br> ALG_SID_MAC = 5;<br> ALG_SID_RIPEMD = 6;<br> ALG_SID_RIPEMD160 = 7;<br> ALG_SID_SSL3SHAMD5 = 8;<br> {Our silly example sub-id }<br> ALG_SID_EXAMPLE = 80;<br><br> {$IFNDEF ALGIDDEF}<br> {$DEFINE ALGIDDEF}<br>type<br> ALG_ID = DWORD; //Cardinal;<br> {$ENDIF}<br><br> {algorithm identifier definitions }<br>const<br> CALG_MD2 = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_MD2);<br> CALG_MD4 = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_MD4);<br> CALG_MD5 = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_MD5);<br> CALG_SHA = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_SHA);<br> CALG_MAC = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_MAC);<br> CALG_RSA_SIGN = (ALG_CLASS_SIGNATURE or ALG_TYPE_RSA or ALG_SID_RSA_ANY);<br> CALG_DSS_SIGN = (ALG_CLASS_SIGNATURE or ALG_TYPE_DSS or ALG_SID_DSS_ANY);<br> CALG_RSA_KEYX = (ALG_CLASS_KEY_EXCHANGE or ALG_TYPE_RSA or ALG_SID_RSA_ANY);<br> CALG_DES = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_DES);<br> CALG_RC2 = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_RC2);<br> CALG_RC4 = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_STREAM or ALG_SID_RC4);<br> CALG_SEAL = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_STREAM or ALG_SID_SEAL);<br><br>type<br> VTableProvStruc = record<br> Version :LongInt;<br> FuncVerifyImage :TFarProc;<br> FuncReturnhWnd :TFarProc;<br> end;<br> PVTableProvStruc = ^VTableProvStruc;<br><br>const<br> {dwFlags definitions for CryptAquireContext }<br> CRYPT_VERIFYCONTEXT = $F0000000;<br> CRYPT_NEWKEYSET = $8;<br> CRYPT_DELETEKEYSET = $10;<br> {dwFlag definitions for CryptGenKey }<br> CRYPT_EXPORTABLE = $00000001;<br> CRYPT_USER_PROTECTED = $00000002;<br> CRYPT_CREATE_SALT = $00000004;<br> CRYPT_UPDATE_KEY = $00000008;<br> {exported key blob definitions }<br> SIMPLEBLOB = $1;<br> PUBLICKEYBLOB = $6;<br> PRIVATEKEYBLOB = $7;<br> AT_KEYEXCHANGE = 1;<br> AT_SIGNATURE = 2;<br> CRYPT_USERDATA = 1;<br> {dwParam }<br> KP_IV = 1; {Initialization vector}<br> KP_SALT = 2; {Salt value}<br> KP_PADDING = 3; {Padding values}<br> KP_MODE = 4; {Mode of the cipher}<br> KP_MODE_BITS = 5; {Number of bits to feedback}<br> KP_PERMISSIONS = 6; {Key permissions DWORD}<br> KP_ALGID = 7; {Key algorithm}<br> KP_BLOCKLEN = 8; {Block size of the cipher}<br> {KP_PADDING }<br> PKCS5_PADDING = 1; {PKCS 5 (sec 6.2) padding method}<br> {KP_MODE }<br> CRYPT_MODE_CBC = 1; {Cipher block chaining}<br> CRYPT_MODE_ECB = 2; {Electronic code book}<br> CRYPT_MODE_OFB = 3; {Output feedback mode}<br> CRYPT_MODE_CFB = 4; {Cipher feedback mode}<br> CRYPT_MODE_CTS = 5; {Ciphertext stealing mode}<br> {KP_PERMISSIONS }<br> CRYPT_ENCRYPT = $0001; {Allow encryption}<br> CRYPT_DECRYPT = $0002; {Allow decryption}<br> CRYPT_EXPORT = $0004; {Allow key to be exported}<br> CRYPT_READ = $0008; {Allow parameters to be read}<br> CRYPT_WRITE = $0010; {Allow parameters to be set}<br> CRYPT_MAC = $0020; {Allow MACs to be used with key}<br> HP_ALGID = $0001; {Hash algorithm}<br> HP_HASHVAL = $0002; {Hash value}<br> HP_HASHSIZE = $0004; {Hash value size}<br> CRYPT_FAILED = FALSE;<br> CRYPT_SUCCEED = TRUE;<br><br>function RCRYPT_SUCCEEDED(rt :BOOL) :BOOL;<br>function RCRYPT_FAILED(rt :BOOL) :BOOL;<br><br>const<br> {CryptGetProvParam}<br> PP_ENUMALGS = 1;<br> PP_ENUMCONTAINERS = 2;<br> PP_IMPTYPE = 3;<br> PP_NAME = 4;<br> PP_VERSION = 5;<br> PP_CONTAINER = 6;<br> CRYPT_FIRST = 1;<br> CRYPT_NEXT = 2;<br> CRYPT_IMPL_HARDWARE = 1;<br> CRYPT_IMPL_SOFTWARE = 2;<br> CRYPT_IMPL_MIXED = 3;<br> CRYPT_IMPL_UNKNOWN = 4;<br> {CryptSetProvParam}<br> PP_CLIENT_HWND = 1;<br> PROV_RSA_FULL = 1;<br> PROV_RSA_SIG = 2;<br> PROV_DSS = 3;<br> PROV_FORTEZZA = 4;<br> PROV_MS_EXCHANGE = 5;<br> PROV_SSL = 6;<br> {STT defined Providers}<br> PROV_STT_MER = 7;<br> PROV_STT_ACQ = 8;<br> PROV_STT_BRND = 9;<br> PROV_STT_ROOT = 10;<br> PROV_STT_ISS = 11;<br> MS_DEF_PROV_A = 'Microsoft Base Cryptographic Provider v1.0';<br> MS_DEF_PROV_W = 'Microsoft Base Cryptographic Provider v1.0';<br> {$IFDEF UNICODE}<br> MS_DEF_PROV = MS_DEF_PROV_W;<br> {$ELSE}<br> MS_DEF_PROV = MS_DEF_PROV_A;<br> {$ENDIF}<br> MAXUIDLEN = 64;<br> CUR_BLOB_VERSION = 2;<br><br>type<br> PROV_ENUMALGS = record<br> aiAlgid :ALG_ID;<br> dwBitLen :LongInt;<br> dwNameLen :LongInt;<br> szName :array[0..20 - 1] of Char;<br> end;<br> PPROV_ENUMALGS = ^PROV_ENUMALGS;<br><br>type<br> PUBLICKEYSTRUC = record<br> bType :BYTE;<br> bVersion :BYTE;<br> reserved :Word;<br> aiKeyAlg :ALG_ID;<br> end;<br> PPUBLICKEYSTRUC = ^PUBLICKEYSTRUC;<br> BLOBHEADER = PUBLICKEYSTRUC;<br> PBLOBHEADER = ^BLOBHEADER;<br> <br>type<br> RSAPUBKEY = record<br> magic
WORD; // Has to be RSA1<br> bitlen
WORD; // # of bits in modulus<br> pubexp
WORD; // public exponent<br> {Modulus data follows }<br> end;<br> PRSAPUBKEY = ^RSAPUBKEY;<br><br>type<br> HCRYPTPROV = DWORD; //cardinal;<br> PHCRYPTPROV = ^HCRYPTPROV;<br> HCRYPTKEY = DWORD; //cardinal;<br> PHCRYPTKEY = ^HCRYPTKEY;<br> HCRYPTHASH = DWORD; //cardinal;<br> PHCRYPTHASH = ^HCRYPTHASH;<br><br>function CryptAcquireContextA(phProv
HCRYPTPROV;<br> pszContainer
AnsiChar;<br> pszProvider
AnsiChar;<br> dwProvType :LongInt;<br> dwFlags :LongInt) :BOOL;stdcall;<br><br>function CryptAcquireContext(phProv
HCRYPTPROV;<br> pszContainer
AnsiChar;<br> pszProvider
AnsiChar;<br> dwProvType :LongInt;<br> dwFlags :LongInt) :BOOL;stdcall;<br><br>function CryptAcquireContextW(phProv
HCRYPTPROV;<br> pszContainer
WideChar;<br> pszProvider
WideChar;<br> dwProvType :LongInt;<br> dwFlags :LongInt) :BOOL;stdcall;<br><br>function CryptReleaseContext(hProv :HCRYPTPROV;<br> dwFlags :LongInt) :BOOL;stdcall;<br><br>function CryptGenKey(hProv :HCRYPTPROV;<br> Algid :ALG_ID;<br> dwFlags :LongInt;<br> phKey
HCRYPTKEY) :BOOL;stdcall;<br><br>function CryptDeriveKey(hProv :HCRYPTPROV;<br> Algid :ALG_ID;<br> hBaseData :HCRYPTHASH;<br> dwFlags :LongInt;<br> phKey
HCRYPTKEY) :BOOL;stdcall;<br><br>function CryptDestroyKey(hKey :HCRYPTKEY) :BOOL;stdcall;<br><br>function CryptSetKeyParam(hKey :HCRYPTKEY;<br> dwParam :LongInt;<br> pbData
BYTE;<br> dwFlags :LongInt) :BOOL;stdcall;<br><br>function CryptGetKeyParam(hKey :HCRYPTKEY;<br> dwParam :LongInt;<br> pbData
BYTE;<br> pdwDataLen
LongInt;<br> dwFlags :LongInt) :BOOL;stdcall;<br><br>function CryptSetHashParam(hHash :HCRYPTHASH;<br> dwParam :LongInt;<br> pbData
BYTE;<br> dwFlags :LongInt) :BOOL;stdcall;<br><br>function CryptGetHashParam(hHash :HCRYPTHASH;<br> dwParam :LongInt;<br> pbData
BYTE;<br> pdwDataLen
LongInt;<br> dwFlags :LongInt) :BOOL;stdcall;<br><br>function CryptSetProvParam(hProv :HCRYPTPROV;<br> dwParam :LongInt;<br> pbData
BYTE;<br> dwFlags :LongInt) :BOOL;stdcall;<br><br>function CryptGetProvParam(hProv :HCRYPTPROV;<br> dwParam :LongInt;<br> pbData
BYTE;<br> pdwDataLen
LongInt;<br> dwFlags :LongInt) :BOOL;stdcall;<br><br>function CryptGenRandom(hProv :HCRYPTPROV;<br> dwLen :LongInt;<br> pbBuffer
BYTE) :BOOL;stdcall;<br><br>function CryptGetUserKey(hProv :HCRYPTPROV;<br> dwKeySpec :LongInt;<br> phUserKey
HCRYPTKEY) :BOOL;stdcall;<br><br>function CryptExportKey(hKey :HCRYPTKEY;<br> hExpKey :HCRYPTKEY;<br> dwBlobType :LongInt;<br> dwFlags :LongInt;<br> pbData
BYTE;<br> pdwDataLen
LongInt) :BOOL;stdcall;<br><br>function CryptImportKey(hProv :HCRYPTPROV;<br> pbData
BYTE;<br> dwDataLen :LongInt;<br> hPubKey :HCRYPTKEY;<br> dwFlags :LongInt;<br> phKey
HCRYPTKEY) :BOOL;stdcall;<br><br>function CryptEncrypt(hKey :HCRYPTKEY;<br> hHash :HCRYPTHASH;<br> Final :Bool;<br> dwFlags :LongInt;<br> pbData
BYTE;<br> pdwDataLen
LongInt;<br> dwBufLen :LongInt) :BOOL;stdcall;<br><br>function CryptDecrypt(hKey :HCRYPTKEY;<br> hHash :HCRYPTHASH;<br> Final :Bool;<br> dwFlags :LongInt;<br> pbData
BYTE;<br> pdwDataLen
LongInt) :BOOL;stdcall;<br><br>function CryptCreateHash(hProv :HCRYPTPROV;<br> Algid :ALG_ID;<br> hKey :HCRYPTKEY;<br> dwFlags :LongInt;<br> phHash
HCRYPTHASH) :BOOL;stdcall;<br><br>function CryptHashData(hHash :HCRYPTHASH;<br> pbData
BYTE;<br> dwDataLen :LongInt;<br> dwFlags :LongInt) :BOOL;stdcall;<br><br>function CryptHashSessionKey(hHash :HCRYPTHASH;<br> hKey :HCRYPTKEY;<br> dwFlags :LongInt) :BOOL;stdcall;<br><br>function CryptDestroyHash(hHash :HCRYPTHASH) :BOOL;stdcall;<br><br>function CryptSignHashA(hHash :HCRYPTHASH;<br> dwKeySpec :LongInt;<br> sDescription
AnsiChar;<br> dwFlags :LongInt;<br> pbSignature
BYTE;<br> pdwSigLen
LongInt) :BOOL;stdcall;<br><br>function CryptSignHash(hHash :HCRYPTHASH;<br> dwKeySpec :LongInt;<br> sDescription
AnsiChar;<br> dwFlags :LongInt;<br> pbSignature
BYTE;<br> pdwSigLen
LongInt) :BOOL;stdcall;<br><br>function CryptSignHashW(hHash :HCRYPTHASH;<br> dwKeySpec :LongInt;<br> sDescription
WideChar;<br> dwFlags :LongInt;<br> pbSignature
BYTE;<br> pdwSigLen
LongInt) :BOOL;stdcall;<br><br>function CryptVerifySignatureA(hHash :HCRYPTHASH;<br> pbSignature
BYTE;<br> dwSigLen :LongInt;<br> hPubKey :HCRYPTKEY;<br> sDescription
AnsiChar;<br> dwFlags :LongInt) :BOOL;stdcall;<br><br>function CryptVerifySignature(hHash :HCRYPTHASH;<br> pbSignature
BYTE;<br> dwSigLen :LongInt;<br> hPubKey :HCRYPTKEY;<br> sDescription
AnsiChar;<br> dwFlags :LongInt) :BOOL;stdcall;<br><br>function CryptVerifySignatureW(hHash :HCRYPTHASH;<br> pbSignature
BYTE;<br> dwSigLen :LongInt;<br> hPubKey :HCRYPTKEY;<br> sDescription
WideChar;<br> dwFlags :LongInt) :BOOL;stdcall;<br><br><br>function CryptSetProviderA(pszProvName
AnsiChar;<br> dwProvType :LongInt) :BOOL;stdcall;<br><br>function CryptSetProvider(pszProvName
AnsiChar;<br> dwProvType :LongInt) :BOOL;stdcall;<br><br>function CryptSetProviderW(pszProvName
WideChar;<br> dwProvType :LongInt) :BOOL;stdcall;<br><br>implementation<br><br>{Macro inplementation}<br><br>function GET_ALG_CLASS(x :integer) :integer;<br>begin<br> Result := (x and (7 shl 13));<br>end;<br><br>function GET_ALG_TYPE(x :integer) :integer;<br>begin<br> Result := (x and (15 shl 9));<br>end;<br><br>function GET_ALG_SID(x :integer) :integer;<br>begin<br> Result := (x and (511));<br>end;<br><br>function RCRYPT_SUCCEEDED(rt :BOOL) :BOOL;<br>begin<br> Result := rt = CRYPT_SUCCEED;<br>end;<br><br>function RCRYPT_FAILED(rt :BOOL) :BOOL;<br>begin<br> Result := rt = CRYPT_FAILED;<br>end;<br>{end Macro}<br><br>function CryptAcquireContextA;external CryptDll name 'CryptAcquireContextA';<br>{$IFDEF UNICODE}<br>function CryptAcquireContext;external CryptDll name 'CryptAcquireContextW';<br>{$ELSE}<br>function CryptAcquireContext;external CryptDll name 'CryptAcquireContextA';<br>{$ENDIF}<br>function CryptAcquireContextW;external CryptDll name 'CryptAcquireContextW';<br>function CryptReleaseContext;external CryptDll name 'CryptReleaseContext';<br>function CryptGenKey;external CryptDll name 'CryptGenKey';<br>function CryptDeriveKey;external CryptDll name 'CryptDeriveKey';<br>function CryptDestroyKey;external CryptDll name 'CryptDestroyKey';<br>function CryptSetKeyParam;external CryptDll name 'CryptSetKeyParam';<br>function CryptGetKeyParam;external CryptDll name 'CryptGetKeyParam';<br>function CryptSetHashParam;external CryptDll name 'CryptSetHashParam';<br>function CryptGetHashParam;external CryptDll name 'CryptGetHashParam';<br>function CryptSetProvParam;external CryptDll name 'CryptSetProvParam';<br>function CryptGetProvParam;external CryptDll name 'CryptGetProvParam';<br>function CryptGenRandom;external CryptDll name 'CryptGenRandom';<br>function CryptGetUserKey;external CryptDll name 'CryptGetUserKey';<br>function CryptExportKey;external CryptDll name 'CryptExportKey';<br>function CryptImportKey;external CryptDll name 'CryptImportKey';<br>function CryptEncrypt;external CryptDll name 'CryptEncrypt';<br>function CryptDecrypt;external CryptDll name 'CryptDecrypt';<br>function CryptCreateHash;external CryptDll name 'CryptCreateHash';<br>function CryptHashData;external CryptDll name 'CryptHashData';<br>function CryptHashSessionKey;external CryptDll name 'CryptHashSessionKey';<br>function CryptDestroyHash;external CryptDll name 'CryptDestroyHash';<br>function CryptSignHashA;external CryptDll name 'CryptSignHashA';<br>{$IFDEF UNICODE}<br>function CryptSignHash;external CryptDll name 'CryptSignHashW';<br>{$ELSE}<br>function CryptSignHash;external CryptDll name 'CryptSignHashA';<br>{$ENDIF}<br>function CryptSignHashW;external CryptDll name 'CryptSignHashW';<br>function CryptVerifySignatureA;external CryptDll name 'CryptVerifySignatureA';<br>{$IFDEF UNICODE}<br>function CryptVerifySignature;external CryptDll name 'CryptVerifySignatureW';<br>{$ELSE}<br>function CryptVerifySignature;external CryptDll name 'CryptVerifySignatureA';<br>{$ENDIF}<br>function CryptVerifySignatureW;external CryptDll name 'CryptVerifySignatureW';<br>function CryptSetProviderA;external CryptDll name 'CryptSetProviderA';<br>{$IFDEF UNICODE}<br>function CryptSetProvider;external CryptDll name 'CryptSetProviderW';<br>{$ELSE}<br>function CryptSetProvider;external CryptDll name 'CryptSetProviderA';<br>{$ENDIF}<br>function CryptSetProviderW;external CryptDll name 'CryptSetProviderW';<br><br>end.<br><br>