P pwxwabcd Unregistered / Unconfirmed GUEST, unregistred user! 2003-06-02 #1 请教CryptoApi用Delphi的实现<br>1.公钥,私钥生成<br>2.加密<br>3.验证<br>4.证书
T thx1180 Unregistered / Unconfirmed GUEST, unregistred user! 2003-06-04 #2 {---------------------------------------------------------<br>Copyright (c) 1996-97 Massimo Maria Ghisalberti<br>CopyRight (c) 1996-97 MAx!<br>CopyRight (c) 1996-97 Objects Built for you! (O.B.you!)<br>Internet EMail: roentgen@mbox.vol.it<br><br>translate from: wincrypt.h<br>date: mm/gg/yy<br>version: 2beta.<br><br>note: use at own risk.<br> If you use this code, please mention O.B.you!<br> somewhere in your program<br><br><br>----------------------------------------------------------<br>IMPORTANT : USE ONLY IF YOU HAVE WINDOWS NT 4.X OR WINDOWS<br>95 OSR2 OR/AND INTERNET EXPLORER 3.X.<br>----------------------------------------------------------}<br><br>unit wincrypt;<br><br>interface<br><br>uses<br> Windows;<br> <br>const CryptDll = 'advapi32';<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><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 ALG_ID = 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 VTableProvStruc = record<br> Version: LongInt;<br> FuncVerifyImage: TFarProc;<br> FuncReturnhWnd: TFarProc;<br>end;<br> PVTableProvStruc = ^VTableProvStruc;<br><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><br>type 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><br>type PUBLICKEYSTRUC = record<br> bType :BYTE;<br> bVersion :BYTE;<br> reserved :Word;<br> aiKeyAlg :ALG_ID;<br>end;<br> PPUBLICKEYSTRUC = ^PUBLICKEYSTRUC;<br><br>type RSAPUBKEY = record<br> magic :LongInt;<br>{ DWORD bitlen; // # of bits in modulus }<br> pubexp :LongInt;<br>{Modulus data follows }<br>end;<br> PRSAPUBKEY = ^RSAPUBKEY;<br><br>type <br> HCRYPTPROV = cardinal;<br> PHCRYPTPROV = ^HCRYPTPROV;<br> HCRYPTKEY = cardinal;<br> PHCRYPTKEY = ^HCRYPTKEY;<br> HCRYPTHASH = 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><br>function CryptReleaseContext(hProv :HCRYPTPROV; <br> dwFlags :LongInt) :BOOL;stdcall;<br><br><br><br>function CryptGenKey(hProv :HCRYPTPROV; <br> Algid :ALG_ID; <br> dwFlags :LongInt; <br> phKey HCRYPTKEY) :BOOL;stdcall ; <br><br><br>function CryptDeriveKey(hProv :HCRYPTPROV; <br> Algid :ALG_ID; <br> hBaseData :HCRYPTHASH; <br> dwFlags :LongInt; <br> phKey HCRYPTKEY) :BOOL;stdcall ; <br><br><br><br>function CryptDestroyKey(hKey :HCRYPTKEY) :BOOL;stdcall ; <br><br><br>function CryptSetKeyParam(hKey :HCRYPTKEY; <br> dwParam :LongInt; <br> pbData BYTE; <br> dwFlags :LongInt) :BOOL;stdcall; <br><br><br>function CryptGetKeyParam(hKey :HCRYPTKEY; <br> dwParam :LongInt; <br> pbData BYTE; <br> pdwDataLen LongInt; <br> dwFlags :LongInt) :BOOL;stdcall;<br><br><br>function CryptSetHashParam(hHash :HCRYPTHASH; <br> dwParam :LongInt; <br> pbData BYTE; <br> dwFlags:LongInt) :BOOL;stdcall;<br><br><br>function CryptGetHashParam(hHash :HCRYPTHASH; <br> dwParam :LongInt; <br> pbData BYTE; <br> pdwDataLen LongInt; <br> dwFlags :LongInt) :BOOL;stdcall; <br><br><br>function CryptSetProvParam(hProv :HCRYPTPROV; <br> dwParam :LongInt; <br> pbData BYTE; <br> dwFlags :LongInt) :BOOL;stdcall;<br><br><br>function CryptGetProvParam(hProv :HCRYPTPROV; <br> dwParam :LongInt; <br> pbData BYTE; <br> pdwDataLen LongInt; <br> dwFlags :LongInt) :BOOL;stdcall;<br><br><br>function CryptGenRandom(hProv :HCRYPTPROV; <br> dwLen :LongInt; <br> pbBuffer BYTE) :BOOL;stdcall;<br><br><br>function CryptGetUserKey(hProv :HCRYPTPROV; <br> dwKeySpec :LongInt; <br> phUserKey HCRYPTKEY) :BOOL;stdcall;<br><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><br>function CryptImportKey(hProv :HCRYPTPROV; <br> pbData BYTE; <br> dwDataLen :LongInt; <br> hPubKey :HCRYPTKEY; <br> dwFlags :LongInt; <br> phKey HCRYPTKEY) :BOOL;stdcall; <br><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><br>function CryptDecrypt(hKey :HCRYPTKEY; <br> hHash :HCRYPTHASH; <br> Final :Bool; <br> dwFlags :LongInt; <br> pbData BYTE; <br> pdwDataLen LongInt) :BOOL;stdcall; <br><br><br>function CryptCreateHash(hProv :HCRYPTPROV; <br> Algid :ALG_ID; <br> hKey :HCRYPTKEY; <br> dwFlags :LongInt; <br> phHash HCRYPTHASH) :BOOL;stdcall;<br><br><br>function CryptHashData(hHash :HCRYPTHASH; <br> pbData BYTE; <br> dwDataLen :LongInt; <br> dwFlags :LongInt) :BOOL;stdcall; <br><br><br>function CryptHashSessionKey(hHash :HCRYPTHASH; <br> hKey :HCRYPTKEY; <br> dwFlags :LongInt) :BOOL;stdcall; <br><br><br>function CryptDestroyHash(hHash :HCRYPTHASH) :BOOL;stdcall; <br><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> <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><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><br>implementation<br><br><br>end.<br>
{---------------------------------------------------------<br>Copyright (c) 1996-97 Massimo Maria Ghisalberti<br>CopyRight (c) 1996-97 MAx!<br>CopyRight (c) 1996-97 Objects Built for you! (O.B.you!)<br>Internet EMail: roentgen@mbox.vol.it<br><br>translate from: wincrypt.h<br>date: mm/gg/yy<br>version: 2beta.<br><br>note: use at own risk.<br> If you use this code, please mention O.B.you!<br> somewhere in your program<br><br><br>----------------------------------------------------------<br>IMPORTANT : USE ONLY IF YOU HAVE WINDOWS NT 4.X OR WINDOWS<br>95 OSR2 OR/AND INTERNET EXPLORER 3.X.<br>----------------------------------------------------------}<br><br>unit wincrypt;<br><br>interface<br><br>uses<br> Windows;<br> <br>const CryptDll = 'advapi32';<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><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 ALG_ID = 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 VTableProvStruc = record<br> Version: LongInt;<br> FuncVerifyImage: TFarProc;<br> FuncReturnhWnd: TFarProc;<br>end;<br> PVTableProvStruc = ^VTableProvStruc;<br><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><br>type 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><br>type PUBLICKEYSTRUC = record<br> bType :BYTE;<br> bVersion :BYTE;<br> reserved :Word;<br> aiKeyAlg :ALG_ID;<br>end;<br> PPUBLICKEYSTRUC = ^PUBLICKEYSTRUC;<br><br>type RSAPUBKEY = record<br> magic :LongInt;<br>{ DWORD bitlen; // # of bits in modulus }<br> pubexp :LongInt;<br>{Modulus data follows }<br>end;<br> PRSAPUBKEY = ^RSAPUBKEY;<br><br>type <br> HCRYPTPROV = cardinal;<br> PHCRYPTPROV = ^HCRYPTPROV;<br> HCRYPTKEY = cardinal;<br> PHCRYPTKEY = ^HCRYPTKEY;<br> HCRYPTHASH = 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><br>function CryptReleaseContext(hProv :HCRYPTPROV; <br> dwFlags :LongInt) :BOOL;stdcall;<br><br><br><br>function CryptGenKey(hProv :HCRYPTPROV; <br> Algid :ALG_ID; <br> dwFlags :LongInt; <br> phKey HCRYPTKEY) :BOOL;stdcall ; <br><br><br>function CryptDeriveKey(hProv :HCRYPTPROV; <br> Algid :ALG_ID; <br> hBaseData :HCRYPTHASH; <br> dwFlags :LongInt; <br> phKey HCRYPTKEY) :BOOL;stdcall ; <br><br><br><br>function CryptDestroyKey(hKey :HCRYPTKEY) :BOOL;stdcall ; <br><br><br>function CryptSetKeyParam(hKey :HCRYPTKEY; <br> dwParam :LongInt; <br> pbData BYTE; <br> dwFlags :LongInt) :BOOL;stdcall; <br><br><br>function CryptGetKeyParam(hKey :HCRYPTKEY; <br> dwParam :LongInt; <br> pbData BYTE; <br> pdwDataLen LongInt; <br> dwFlags :LongInt) :BOOL;stdcall;<br><br><br>function CryptSetHashParam(hHash :HCRYPTHASH; <br> dwParam :LongInt; <br> pbData BYTE; <br> dwFlags:LongInt) :BOOL;stdcall;<br><br><br>function CryptGetHashParam(hHash :HCRYPTHASH; <br> dwParam :LongInt; <br> pbData BYTE; <br> pdwDataLen LongInt; <br> dwFlags :LongInt) :BOOL;stdcall; <br><br><br>function CryptSetProvParam(hProv :HCRYPTPROV; <br> dwParam :LongInt; <br> pbData BYTE; <br> dwFlags :LongInt) :BOOL;stdcall;<br><br><br>function CryptGetProvParam(hProv :HCRYPTPROV; <br> dwParam :LongInt; <br> pbData BYTE; <br> pdwDataLen LongInt; <br> dwFlags :LongInt) :BOOL;stdcall;<br><br><br>function CryptGenRandom(hProv :HCRYPTPROV; <br> dwLen :LongInt; <br> pbBuffer BYTE) :BOOL;stdcall;<br><br><br>function CryptGetUserKey(hProv :HCRYPTPROV; <br> dwKeySpec :LongInt; <br> phUserKey HCRYPTKEY) :BOOL;stdcall;<br><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><br>function CryptImportKey(hProv :HCRYPTPROV; <br> pbData BYTE; <br> dwDataLen :LongInt; <br> hPubKey :HCRYPTKEY; <br> dwFlags :LongInt; <br> phKey HCRYPTKEY) :BOOL;stdcall; <br><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><br>function CryptDecrypt(hKey :HCRYPTKEY; <br> hHash :HCRYPTHASH; <br> Final :Bool; <br> dwFlags :LongInt; <br> pbData BYTE; <br> pdwDataLen LongInt) :BOOL;stdcall; <br><br><br>function CryptCreateHash(hProv :HCRYPTPROV; <br> Algid :ALG_ID; <br> hKey :HCRYPTKEY; <br> dwFlags :LongInt; <br> phHash HCRYPTHASH) :BOOL;stdcall;<br><br><br>function CryptHashData(hHash :HCRYPTHASH; <br> pbData BYTE; <br> dwDataLen :LongInt; <br> dwFlags :LongInt) :BOOL;stdcall; <br><br><br>function CryptHashSessionKey(hHash :HCRYPTHASH; <br> hKey :HCRYPTKEY; <br> dwFlags :LongInt) :BOOL;stdcall; <br><br><br>function CryptDestroyHash(hHash :HCRYPTHASH) :BOOL;stdcall; <br><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> <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><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><br>implementation<br><br><br>end.<br>
T thx1180 Unregistered / Unconfirmed GUEST, unregistred user! 2003-06-05 #4 http://homepages.borland.com/efg2lab/Library/Delphi/MathFunctions/BerndLehmannCrypto.zip
P pwxwabcd Unregistered / Unconfirmed GUEST, unregistred user! 2003-06-06 #5 楼上的朋友提供的例子不能正常执行,不过还是谢谢。
T thx1180 Unregistered / Unconfirmed GUEST, unregistred user! 2003-06-06 #6 你自己到这里找找吧:<br>http://homepages.borland.com/efg2lab/Library/Delphi/MathFunctions/Cryptography.htm
P pwxwabcd Unregistered / Unconfirmed GUEST, unregistred user! 2003-06-11 #7 楼上的朋友提供的连接地址只有头文件,没有delphi实际的例子.
T thx1180 Unregistered / Unconfirmed GUEST, unregistred user! 2003-06-11 #8 怎么没有啊,这个是全的:<br>ftp://delphi-jedi.org/api/CryptoAPI1.zip
I itren Unregistered / Unconfirmed GUEST, unregistred user! 2003-06-11 #9 Enjoy This Samples hehe!<br>http://delphi.ur-solution.com/delphi_download/upload/29919_CryptSample.zip
Enjoy This Samples hehe!<br>http://delphi.ur-solution.com/delphi_download/upload/29919_CryptSample.zip
P pwxwabcd Unregistered / Unconfirmed GUEST, unregistred user! 2003-06-16 #10 证书如何生成,如何在不通过文件导入导出获得私钥。