JwaWinCrypt.pas
上传用户:davidchvip
上传日期:2009-07-28
资源大小:1749k
文件大小:773k
源码类别:

Windows编程

开发平台:

Delphi

  1. {******************************************************************************}
  2. {                                                                       }
  3. { Windows Cryptography API interface Unit for Object Pascal                    }
  4. {                                                                       }
  5. { Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft          }
  6. { Corporation. All Rights Reserved.                                            }
  7. {                 }
  8. { The original file is: wincrypt.h, released June 2000. The original Pascal    }
  9. { code is: WinCrypt.pas, released December 2000. The initial developer of the  }
  10. { Pascal code is Marcel van Brakel (brakelm@chello.nl).                        }
  11. {                                                                              }
  12. { Portions created by Marcel van Brakel are Copyright (C) 1999-2001            }
  13. { Marcel van Brakel. All Rights Reserved.                                      }
  14. {                 }
  15. { Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI)        }
  16. {                }
  17. { You may retrieve the latest version of this file at the Project JEDI home    }
  18. { page, located at http://delphi-jedi.org or my personal homepage located at   }
  19. { http://members.chello.nl/m.vanbrakel2                                        }
  20. {                }
  21. { The contents of this file are used with permission, subject to the Mozilla   }
  22. { Public License Version 1.1 (the "License"); you may not use this file except }
  23. { in compliance with the License. You may obtain a copy of the License at      }
  24. { http://www.mozilla.org/MPL/MPL-1.1.html                                      }
  25. {                                                                              }
  26. { Software distributed under the License is distributed on an "AS IS" basis,   }
  27. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  28. { the specific language governing rights and limitations under the License.    }
  29. {                                                                              }
  30. { Alternatively, the contents of this file may be used under the terms of the  }
  31. { GNU Lesser General Public License (the  "LGPL License"), in which case the   }
  32. { provisions of the LGPL License are applicable instead of those above.        }
  33. { If you wish to allow use of your version of this file only under the terms   }
  34. { of the LGPL License and not to allow others to use your version of this file }
  35. { under the MPL, indicate your decision by deleting  the provisions above and  }
  36. { replace  them with the notice and other provisions required by the LGPL      }
  37. { License.  If you do not delete the provisions above, a recipient may use     }
  38. { your version of this file under either the MPL or the LGPL License.          }
  39. {                 }
  40. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  41. {                 }
  42. {******************************************************************************}
  43. unit JwaWinCrypt;
  44. {$WEAKPACKAGEUNIT}
  45. {$HPPEMIT ''}
  46. {$HPPEMIT '#include <WinCrypt.h>'}
  47. {$HPPEMIT ''}
  48. {$HPPEMIT 'typedef HCRYPTPROV *PHCRYPTPROV'}
  49. {$HPPEMIT 'typedef HCRYPTKEY *PHCRYPTKEY'}
  50. {$HPPEMIT 'typedef HCRYPTHASH *PHCRYPTHASH'}
  51. {$HPPEMIT 'typedef PROV_ENUMALGS *PPROV_ENUMALGS'}
  52. {$HPPEMIT 'typedef PROV_ENUMALGS_EX *PPROV_ENUMALGS_EX'}
  53. {$HPPEMIT 'typedef PUBLICKEYSTRUC *PPUBLICKEYSTRUC'}
  54. {$HPPEMIT 'typedef RSAPUBKEY *PRSAPUBKEY'}
  55. {$HPPEMIT 'typedef DSSSEED *PDSSSEED'}
  56. {$HPPEMIT 'typedef PUBKEYVER3 *PPUBKEYVER3'}
  57. {$HPPEMIT 'typedef DHPRIVKEY_VER3 *PPRIVKEYVER3'}
  58. {$HPPEMIT 'typedef CERT_FORTEZZA_DATA_PROP *PCERT_FORTEZZA_DATA_PROP'}
  59. {$HPPEMIT 'typedef HCRYPTMSG *PHCRYPTMSG'}
  60. {$HPPEMIT 'typedef CMSG_RECIPIENT_ENCODE_INFO *PCMSG_RECIPIENT_ENCODE_INFO'}
  61. {$HPPEMIT 'typedef _CMSG_RECIPIENT_ENCODE_INFO CMSG_RECIPIENT_ENCODE_INFO'}
  62. {$HPPEMIT 'typedef PCMSG_KEY_AGREE_KEY_ENCRYPT_INFO *PPCMSG_KEY_AGREE_KEY_ENCRYPT_INFO'}
  63. {$HPPEMIT 'typedef HCERTSTORE *PHCERTSTORE'}
  64. {$HPPEMIT 'typedef PCCERT_CONTEXT *PPCCERT_CONTEXT'}
  65. {$HPPEMIT 'typedef PCCRL_CONTEXT *PPCCRL_CONTEXT'}
  66. {$HPPEMIT 'typedef PCERT_CHAIN_CONTEXT *PPCCERT_CHAIN_CONTEXT'}
  67. {$HPPEMIT ''}
  68. {$I WINDEFINES.INC}
  69. interface
  70. uses
  71.   JwaWinBase, JwaWinType;
  72. //
  73. // Algorithm IDs and Flags
  74. //
  75. // ALG_ID crackers
  76. function GET_ALG_CLASS(x: DWORD): DWORD;
  77. {$EXTERNALSYM GET_ALG_CLASS}
  78. function GET_ALG_TYPE(x: DWORD): DWORD;
  79. {$EXTERNALSYM GET_ALG_TYPE}
  80. function GET_ALG_SID(x: DWORD): DWORD;
  81. {$EXTERNALSYM GET_ALG_SID}
  82. // Algorithm classes
  83. const
  84.   ALG_CLASS_ANY          = (0);
  85.   {$EXTERNALSYM ALG_CLASS_ANY}
  86.   ALG_CLASS_SIGNATURE    = (1 shl 13);
  87.   {$EXTERNALSYM ALG_CLASS_SIGNATURE}
  88.   ALG_CLASS_MSG_ENCRYPT  = (2 shl 13);
  89.   {$EXTERNALSYM ALG_CLASS_MSG_ENCRYPT}
  90.   ALG_CLASS_DATA_ENCRYPT = (3 shl 13);
  91.   {$EXTERNALSYM ALG_CLASS_DATA_ENCRYPT}
  92.   ALG_CLASS_HASH         = (4 shl 13);
  93.   {$EXTERNALSYM ALG_CLASS_HASH}
  94.   ALG_CLASS_KEY_EXCHANGE = (5 shl 13);
  95.   {$EXTERNALSYM ALG_CLASS_KEY_EXCHANGE}
  96.   ALG_CLASS_ALL          = (7 shl 13);
  97.   {$EXTERNALSYM ALG_CLASS_ALL}
  98. // Algorithm types
  99.   ALG_TYPE_ANY           = (0);
  100.   {$EXTERNALSYM ALG_TYPE_ANY}
  101.   ALG_TYPE_DSS           = (1 shl 9);
  102.   {$EXTERNALSYM ALG_TYPE_DSS}
  103.   ALG_TYPE_RSA           = (2 shl 9);
  104.   {$EXTERNALSYM ALG_TYPE_RSA}
  105.   ALG_TYPE_BLOCK         = (3 shl 9);
  106.   {$EXTERNALSYM ALG_TYPE_BLOCK}
  107.   ALG_TYPE_STREAM        = (4 shl 9);
  108.   {$EXTERNALSYM ALG_TYPE_STREAM}
  109.   ALG_TYPE_DH            = (5 shl 9);
  110.   {$EXTERNALSYM ALG_TYPE_DH}
  111.   ALG_TYPE_SECURECHANNEL = (6 shl 9);
  112.   {$EXTERNALSYM ALG_TYPE_SECURECHANNEL}
  113. // Generic sub-ids
  114.   ALG_SID_ANY = (0);
  115.   {$EXTERNALSYM ALG_SID_ANY}
  116. // Some RSA sub-ids
  117.   ALG_SID_RSA_ANY      = 0;
  118.   {$EXTERNALSYM ALG_SID_RSA_ANY}
  119.   ALG_SID_RSA_PKCS     = 1;
  120.   {$EXTERNALSYM ALG_SID_RSA_PKCS}
  121.   ALG_SID_RSA_MSATWORK = 2;
  122.   {$EXTERNALSYM ALG_SID_RSA_MSATWORK}
  123.   ALG_SID_RSA_ENTRUST  = 3;
  124.   {$EXTERNALSYM ALG_SID_RSA_ENTRUST}
  125.   ALG_SID_RSA_PGP      = 4;
  126.   {$EXTERNALSYM ALG_SID_RSA_PGP}
  127. // Some DSS sub-ids
  128. //
  129.   ALG_SID_DSS_ANY  = 0;
  130.   {$EXTERNALSYM ALG_SID_DSS_ANY}
  131.   ALG_SID_DSS_PKCS = 1;
  132.   {$EXTERNALSYM ALG_SID_DSS_PKCS}
  133.   ALG_SID_DSS_DMS  = 2;
  134.   {$EXTERNALSYM ALG_SID_DSS_DMS}
  135. // Block cipher sub ids
  136. // DES sub_ids
  137.   ALG_SID_DES        = 1;
  138.   {$EXTERNALSYM ALG_SID_DES}
  139.   ALG_SID_3DES       = 3;
  140.   {$EXTERNALSYM ALG_SID_3DES}
  141.   ALG_SID_DESX       = 4;
  142.   {$EXTERNALSYM ALG_SID_DESX}
  143.   ALG_SID_IDEA       = 5;
  144.   {$EXTERNALSYM ALG_SID_IDEA}
  145.   ALG_SID_CAST       = 6;
  146.   {$EXTERNALSYM ALG_SID_CAST}
  147.   ALG_SID_SAFERSK64  = 7;
  148.   {$EXTERNALSYM ALG_SID_SAFERSK64}
  149.   ALG_SID_SAFERSK128 = 8;
  150.   {$EXTERNALSYM ALG_SID_SAFERSK128}
  151.   ALG_SID_3DES_112   = 9;
  152.   {$EXTERNALSYM ALG_SID_3DES_112}
  153.   ALG_SID_CYLINK_MEK = 12;
  154.   {$EXTERNALSYM ALG_SID_CYLINK_MEK}
  155.   ALG_SID_RC5        = 13;
  156.   {$EXTERNALSYM ALG_SID_RC5}
  157. // Fortezza sub-ids
  158.   ALG_SID_SKIPJACK = 10;
  159.   {$EXTERNALSYM ALG_SID_SKIPJACK}
  160.   ALG_SID_TEK      = 11;
  161.   {$EXTERNALSYM ALG_SID_TEK}
  162. // KP_MODE
  163.   CRYPT_MODE_CBCI    = 6; // ANSI CBC Interleaved
  164.   {$EXTERNALSYM CRYPT_MODE_CBCI}
  165.   CRYPT_MODE_CFBP    = 7; // ANSI CFB Pipelined
  166.   {$EXTERNALSYM CRYPT_MODE_CFBP}
  167.   CRYPT_MODE_OFBP    = 8; // ANSI OFB Pipelined
  168.   {$EXTERNALSYM CRYPT_MODE_OFBP}
  169.   CRYPT_MODE_CBCOFM  = 9; // ANSI CBC + OF Masking
  170.   {$EXTERNALSYM CRYPT_MODE_CBCOFM}
  171.   CRYPT_MODE_CBCOFMI = 10; // ANSI CBC + OFM Interleaved
  172.   {$EXTERNALSYM CRYPT_MODE_CBCOFMI}
  173. // RC2 sub-ids
  174.   ALG_SID_RC2 = 2;
  175.   {$EXTERNALSYM ALG_SID_RC2}
  176. // Stream cipher sub-ids
  177.   ALG_SID_RC4  = 1;
  178.   {$EXTERNALSYM ALG_SID_RC4}
  179.   ALG_SID_SEAL = 2;
  180.   {$EXTERNALSYM ALG_SID_SEAL}
  181. // Diffie-Hellman sub-ids
  182.   ALG_SID_DH_SANDF       = 1;
  183.   {$EXTERNALSYM ALG_SID_DH_SANDF}
  184.   ALG_SID_DH_EPHEM       = 2;
  185.   {$EXTERNALSYM ALG_SID_DH_EPHEM}
  186.   ALG_SID_AGREED_KEY_ANY = 3;
  187.   {$EXTERNALSYM ALG_SID_AGREED_KEY_ANY}
  188.   ALG_SID_KEA            = 4;
  189.   {$EXTERNALSYM ALG_SID_KEA}
  190. // Hash sub ids
  191.   ALG_SID_MD2        = 1;
  192.   {$EXTERNALSYM ALG_SID_MD2}
  193.   ALG_SID_MD4        = 2;
  194.   {$EXTERNALSYM ALG_SID_MD4}
  195.   ALG_SID_MD5        = 3;
  196.   {$EXTERNALSYM ALG_SID_MD5}
  197.   ALG_SID_SHA        = 4;
  198.   {$EXTERNALSYM ALG_SID_SHA}
  199.   ALG_SID_SHA1       = 4;
  200.   {$EXTERNALSYM ALG_SID_SHA1}
  201.   ALG_SID_MAC        = 5;
  202.   {$EXTERNALSYM ALG_SID_MAC}
  203.   ALG_SID_RIPEMD     = 6;
  204.   {$EXTERNALSYM ALG_SID_RIPEMD}
  205.   ALG_SID_RIPEMD160  = 7;
  206.   {$EXTERNALSYM ALG_SID_RIPEMD160}
  207.   ALG_SID_SSL3SHAMD5 = 8;
  208.   {$EXTERNALSYM ALG_SID_SSL3SHAMD5}
  209.   ALG_SID_HMAC       = 9;
  210.   {$EXTERNALSYM ALG_SID_HMAC}
  211.   ALG_SID_TLS1PRF    = 10;
  212.   {$EXTERNALSYM ALG_SID_TLS1PRF}
  213. // secure channel sub ids
  214.   ALG_SID_SSL3_MASTER          = 1;
  215.   {$EXTERNALSYM ALG_SID_SSL3_MASTER}
  216.   ALG_SID_SCHANNEL_MASTER_HASH = 2;
  217.   {$EXTERNALSYM ALG_SID_SCHANNEL_MASTER_HASH}
  218.   ALG_SID_SCHANNEL_MAC_KEY     = 3;
  219.   {$EXTERNALSYM ALG_SID_SCHANNEL_MAC_KEY}
  220.   ALG_SID_PCT1_MASTER          = 4;
  221.   {$EXTERNALSYM ALG_SID_PCT1_MASTER}
  222.   ALG_SID_SSL2_MASTER          = 5;
  223.   {$EXTERNALSYM ALG_SID_SSL2_MASTER}
  224.   ALG_SID_TLS1_MASTER          = 6;
  225.   {$EXTERNALSYM ALG_SID_TLS1_MASTER}
  226.   ALG_SID_SCHANNEL_ENC_KEY     = 7;
  227.   {$EXTERNALSYM ALG_SID_SCHANNEL_ENC_KEY}
  228. // Our silly example sub-id
  229.   ALG_SID_EXAMPLE = 80;
  230.   {$EXTERNALSYM ALG_SID_EXAMPLE}
  231. type
  232.   ALG_ID = Cardinal;
  233.   {$EXTERNALSYM ALG_ID}
  234. // algorithm identifier definitions
  235. const
  236.   CALG_MD2                  = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_MD2);
  237.   {$EXTERNALSYM CALG_MD2}
  238.   CALG_MD4                  = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_MD4);
  239.   {$EXTERNALSYM CALG_MD4}
  240.   CALG_MD5                  = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_MD5);
  241.   {$EXTERNALSYM CALG_MD5}
  242.   CALG_SHA                  = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_SHA);
  243.   {$EXTERNALSYM CALG_SHA}
  244.   CALG_SHA1                 = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_SHA1);
  245.   {$EXTERNALSYM CALG_SHA1}
  246.   CALG_MAC                  = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_MAC);
  247.   {$EXTERNALSYM CALG_MAC}
  248.   CALG_RSA_SIGN             = (ALG_CLASS_SIGNATURE or ALG_TYPE_RSA or ALG_SID_RSA_ANY);
  249.   {$EXTERNALSYM CALG_RSA_SIGN}
  250.   CALG_DSS_SIGN             = (ALG_CLASS_SIGNATURE or ALG_TYPE_DSS or ALG_SID_DSS_ANY);
  251.   {$EXTERNALSYM CALG_DSS_SIGN}
  252.   CALG_RSA_KEYX             = (ALG_CLASS_KEY_EXCHANGE or ALG_TYPE_RSA or ALG_SID_RSA_ANY);
  253.   {$EXTERNALSYM CALG_RSA_KEYX}
  254.   CALG_DES                  = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_DES);
  255.   {$EXTERNALSYM CALG_DES}
  256.   CALG_3DES_112             = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_3DES_112);
  257.   {$EXTERNALSYM CALG_3DES_112}
  258.   CALG_3DES                 = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_3DES);
  259.   {$EXTERNALSYM CALG_3DES}
  260.   CALG_DESX                 = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_DESX);
  261.   {$EXTERNALSYM CALG_DESX}
  262.   CALG_RC2                  = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_RC2);
  263.   {$EXTERNALSYM CALG_RC2}
  264.   CALG_RC4                  = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_STREAM or ALG_SID_RC4);
  265.   {$EXTERNALSYM CALG_RC4}
  266.   CALG_SEAL                 = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_STREAM or ALG_SID_SEAL);
  267.   {$EXTERNALSYM CALG_SEAL}
  268.   CALG_DH_SF                = (ALG_CLASS_KEY_EXCHANGE or ALG_TYPE_DH or ALG_SID_DH_SANDF);
  269.   {$EXTERNALSYM CALG_DH_SF}
  270.   CALG_DH_EPHEM             = (ALG_CLASS_KEY_EXCHANGE or ALG_TYPE_DH or ALG_SID_DH_EPHEM);
  271.   {$EXTERNALSYM CALG_DH_EPHEM}
  272.   CALG_AGREEDKEY_ANY        = (ALG_CLASS_KEY_EXCHANGE or ALG_TYPE_DH or ALG_SID_AGREED_KEY_ANY);
  273.   {$EXTERNALSYM CALG_AGREEDKEY_ANY}
  274.   CALG_KEA_KEYX             = (ALG_CLASS_KEY_EXCHANGE or ALG_TYPE_DH or ALG_SID_KEA);
  275.   {$EXTERNALSYM CALG_KEA_KEYX}
  276.   CALG_HUGHES_MD5           = (ALG_CLASS_KEY_EXCHANGE or ALG_TYPE_ANY or ALG_SID_MD5);
  277.   {$EXTERNALSYM CALG_HUGHES_MD5}
  278.   CALG_SKIPJACK             = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_SKIPJACK);
  279.   {$EXTERNALSYM CALG_SKIPJACK}
  280.   CALG_TEK                  = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_TEK);
  281.   {$EXTERNALSYM CALG_TEK}
  282.   CALG_CYLINK_MEK           = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_CYLINK_MEK);
  283.   {$EXTERNALSYM CALG_CYLINK_MEK}
  284.   CALG_SSL3_SHAMD5          = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_SSL3SHAMD5);
  285.   {$EXTERNALSYM CALG_SSL3_SHAMD5}
  286.   CALG_SSL3_MASTER          = (ALG_CLASS_MSG_ENCRYPT or ALG_TYPE_SECURECHANNEL or ALG_SID_SSL3_MASTER);
  287.   {$EXTERNALSYM CALG_SSL3_MASTER}
  288.   CALG_SCHANNEL_MASTER_HASH = (ALG_CLASS_MSG_ENCRYPT or ALG_TYPE_SECURECHANNEL or ALG_SID_SCHANNEL_MASTER_HASH);
  289.   {$EXTERNALSYM CALG_SCHANNEL_MASTER_HASH}
  290.   CALG_SCHANNEL_MAC_KEY     = (ALG_CLASS_MSG_ENCRYPT or ALG_TYPE_SECURECHANNEL or ALG_SID_SCHANNEL_MAC_KEY);
  291.   {$EXTERNALSYM CALG_SCHANNEL_MAC_KEY}
  292.   CALG_SCHANNEL_ENC_KEY     = (ALG_CLASS_MSG_ENCRYPT or ALG_TYPE_SECURECHANNEL or ALG_SID_SCHANNEL_ENC_KEY);
  293.   {$EXTERNALSYM CALG_SCHANNEL_ENC_KEY}
  294.   CALG_PCT1_MASTER          = (ALG_CLASS_MSG_ENCRYPT or ALG_TYPE_SECURECHANNEL or ALG_SID_PCT1_MASTER);
  295.   {$EXTERNALSYM CALG_PCT1_MASTER}
  296.   CALG_SSL2_MASTER          = (ALG_CLASS_MSG_ENCRYPT or ALG_TYPE_SECURECHANNEL or ALG_SID_SSL2_MASTER);
  297.   {$EXTERNALSYM CALG_SSL2_MASTER}
  298.   CALG_TLS1_MASTER          = (ALG_CLASS_MSG_ENCRYPT or ALG_TYPE_SECURECHANNEL or ALG_SID_TLS1_MASTER);
  299.   {$EXTERNALSYM CALG_TLS1_MASTER}
  300.   CALG_RC5                  = (ALG_CLASS_DATA_ENCRYPT or ALG_TYPE_BLOCK or ALG_SID_RC5);
  301.   {$EXTERNALSYM CALG_RC5}
  302.   CALG_HMAC                 = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_HMAC);
  303.   {$EXTERNALSYM CALG_HMAC}
  304.   CALG_TLS1PRF              = (ALG_CLASS_HASH or ALG_TYPE_ANY or ALG_SID_TLS1PRF);
  305.   {$EXTERNALSYM CALG_TLS1PRF}
  306. // resource number for signatures in the CSP
  307.   SIGNATURE_RESOURCE_NUMBER = $29A;
  308.   {$EXTERNALSYM SIGNATURE_RESOURCE_NUMBER}
  309. type
  310.   PVTableProvStruc = ^VTableProvStruc;
  311.   _VTableProvStruc = record
  312.     Version: DWORD;
  313.     FuncVerifyImage: FARPROC;
  314.     FuncReturnhWnd: FARPROC;
  315.     dwProvType: DWORD;
  316.     pbContextInfo: LPBYTE;
  317.     cbContextInfo: DWORD;
  318.     pszProvName: LPSTR;
  319.   end;
  320.   {$EXTERNALSYM _VTableProvStruc}
  321.   VTableProvStruc = _VTableProvStruc;
  322.   {$EXTERNALSYM VTableProvStruc}
  323.   TVTableProvStruc = VTableProvStruc;
  324.   HCRYPTPROV = ULONG_PTR;
  325.   {$EXTERNALSYM HCRYPTPROV}
  326.   HCRYPTKEY = ULONG_PTR;
  327.   {$EXTERNALSYM HCRYPTKEY}
  328.   HCRYPTHASH = ULONG_PTR;
  329.   {$EXTERNALSYM HCRYPTHASH}
  330.   PHCRYPTPROV = ^HCRYPTPROV;
  331.   {$NODEFINE PHCRYPTPROV}
  332.   PHCRYPTKEY = ^HCRYPTKEY;
  333.   {$NODEFINE PHCRYPTKEY}
  334.   PHCRYPTHASH = ^HCRYPTHASH;
  335.   {$NODEFINE PHCRYPTHASH}
  336. // dwFlags definitions for CryptAcquireContext
  337. const
  338.   CRYPT_VERIFYCONTEXT  = DWORD($F0000000);
  339.   {$EXTERNALSYM CRYPT_VERIFYCONTEXT}
  340.   CRYPT_NEWKEYSET      = $00000008;
  341.   {$EXTERNALSYM CRYPT_NEWKEYSET}
  342.   CRYPT_DELETEKEYSET   = $00000010;
  343.   {$EXTERNALSYM CRYPT_DELETEKEYSET}
  344.   CRYPT_MACHINE_KEYSET = $00000020;
  345.   {$EXTERNALSYM CRYPT_MACHINE_KEYSET}
  346.   CRYPT_SILENT         = $00000040;
  347.   {$EXTERNALSYM CRYPT_SILENT}
  348. // dwFlag definitions for CryptGenKey
  349.   CRYPT_EXPORTABLE     = $00000001;
  350.   {$EXTERNALSYM CRYPT_EXPORTABLE}
  351.   CRYPT_USER_PROTECTED = $00000002;
  352.   {$EXTERNALSYM CRYPT_USER_PROTECTED}
  353.   CRYPT_CREATE_SALT    = $00000004;
  354.   {$EXTERNALSYM CRYPT_CREATE_SALT}
  355.   CRYPT_UPDATE_KEY     = $00000008;
  356.   {$EXTERNALSYM CRYPT_UPDATE_KEY}
  357.   CRYPT_NO_SALT        = $00000010;
  358.   {$EXTERNALSYM CRYPT_NO_SALT}
  359.   CRYPT_PREGEN         = $00000040;
  360.   {$EXTERNALSYM CRYPT_PREGEN}
  361.   CRYPT_RECIPIENT      = $00000010;
  362.   {$EXTERNALSYM CRYPT_RECIPIENT}
  363.   CRYPT_INITIATOR      = $00000040;
  364.   {$EXTERNALSYM CRYPT_INITIATOR}
  365.   CRYPT_ONLINE         = $00000080;
  366.   {$EXTERNALSYM CRYPT_ONLINE}
  367.   CRYPT_SF             = $00000100;
  368.   {$EXTERNALSYM CRYPT_SF}
  369.   CRYPT_CREATE_IV      = $00000200;
  370.   {$EXTERNALSYM CRYPT_CREATE_IV}
  371.   CRYPT_KEK            = $00000400;
  372.   {$EXTERNALSYM CRYPT_KEK}
  373.   CRYPT_DATA_KEY       = $00000800;
  374.   {$EXTERNALSYM CRYPT_DATA_KEY}
  375.   CRYPT_VOLATILE       = $00001000;
  376.   {$EXTERNALSYM CRYPT_VOLATILE}
  377.   CRYPT_SGCKEY         = $00002000;
  378.   {$EXTERNALSYM CRYPT_SGCKEY}
  379.   RSA1024BIT_KEY       = $04000000;
  380.   {$EXTERNALSYM RSA1024BIT_KEY}
  381. // dwFlags definitions for CryptDeriveKey
  382.   CRYPT_SERVER = $00000400;
  383.   {$EXTERNALSYM CRYPT_SERVER}
  384.   KEY_LENGTH_MASK = DWORD($FFFF0000);
  385.   {$EXTERNALSYM KEY_LENGTH_MASK}
  386. // dwFlag definitions for CryptExportKey
  387.   CRYPT_Y_ONLY        = $00000001;
  388.   {$EXTERNALSYM CRYPT_Y_ONLY}
  389.   CRYPT_SSL2_FALLBACK = $00000002;
  390.   {$EXTERNALSYM CRYPT_SSL2_FALLBACK}
  391.   CRYPT_DESTROYKEY    = $00000004;
  392.   {$EXTERNALSYM CRYPT_DESTROYKEY}
  393.   CRYPT_OAEP          = $00000040; // used with RSA encryptions/decryptions
  394.                                    // CryptExportKey, CryptImportKey,
  395.                                    // CryptEncrypt and CryptDecrypt
  396.   {$EXTERNALSYM CRYPT_OAEP}
  397.   CRYPT_BLOB_VER3 = $00000080; // export version 3 of a blob type
  398.   {$EXTERNALSYM CRYPT_BLOB_VER3}
  399. // dwFlags definitions for CryptCreateHash
  400.   CRYPT_SECRETDIGEST = $00000001;
  401.   {$EXTERNALSYM CRYPT_SECRETDIGEST}
  402. // dwFlags definitions for CryptHashSessionKey
  403.   CRYPT_LITTLE_ENDIAN = $00000001;
  404.   {$EXTERNALSYM CRYPT_LITTLE_ENDIAN}
  405. // dwFlags definitions for CryptSignHash and CryptVerifySignature
  406.   CRYPT_NOHASHOID    = $00000001;
  407.   {$EXTERNALSYM CRYPT_NOHASHOID}
  408.   CRYPT_TYPE2_FORMAT = $00000002;
  409.   {$EXTERNALSYM CRYPT_TYPE2_FORMAT}
  410.   CRYPT_X931_FORMAT  = $00000004;
  411.   {$EXTERNALSYM CRYPT_X931_FORMAT}
  412. // dwFlag definitions for CryptSetProviderEx and CryptGetDefaultProvider
  413.   CRYPT_MACHINE_DEFAULT = $00000001;
  414.   {$EXTERNALSYM CRYPT_MACHINE_DEFAULT}
  415.   CRYPT_USER_DEFAULT    = $00000002;
  416.   {$EXTERNALSYM CRYPT_USER_DEFAULT}
  417.   CRYPT_DELETE_DEFAULT  = $00000004;
  418.   {$EXTERNALSYM CRYPT_DELETE_DEFAULT}
  419. // exported key blob definitions
  420.   SIMPLEBLOB           = $1;
  421.   {$EXTERNALSYM SIMPLEBLOB}
  422.   PUBLICKEYBLOB        = $6;
  423.   {$EXTERNALSYM PUBLICKEYBLOB}
  424.   PRIVATEKEYBLOB       = $7;
  425.   {$EXTERNALSYM PRIVATEKEYBLOB}
  426.   PLAINTEXTKEYBLOB     = $8;
  427.   {$EXTERNALSYM PLAINTEXTKEYBLOB}
  428.   OPAQUEKEYBLOB        = $9;
  429.   {$EXTERNALSYM OPAQUEKEYBLOB}
  430.   PUBLICKEYBLOBEX      = $A;
  431.   {$EXTERNALSYM PUBLICKEYBLOBEX}
  432.   SYMMETRICWRAPKEYBLOB = $B;
  433.   {$EXTERNALSYM SYMMETRICWRAPKEYBLOB}
  434.   AT_KEYEXCHANGE = 1;
  435.   {$EXTERNALSYM AT_KEYEXCHANGE}
  436.   AT_SIGNATURE   = 2;
  437.   {$EXTERNALSYM AT_SIGNATURE}
  438.   CRYPT_USERDATA = 1;
  439.   {$EXTERNALSYM CRYPT_USERDATA}
  440. // dwParam
  441.   KP_IV               = 1; // Initialization vector
  442.   {$EXTERNALSYM KP_IV}
  443.   KP_SALT             = 2; // Salt value
  444.   {$EXTERNALSYM KP_SALT}
  445.   KP_PADDING          = 3; // Padding values
  446.   {$EXTERNALSYM KP_PADDING}
  447.   KP_MODE             = 4; // Mode of the cipher
  448.   {$EXTERNALSYM KP_MODE}
  449.   KP_MODE_BITS        = 5; // Number of bits to feedback
  450.   {$EXTERNALSYM KP_MODE_BITS}
  451.   KP_PERMISSIONS      = 6; // Key permissions DWORD
  452.   {$EXTERNALSYM KP_PERMISSIONS}
  453.   KP_ALGID            = 7; // Key algorithm
  454.   {$EXTERNALSYM KP_ALGID}
  455.   KP_BLOCKLEN         = 8; // Block size of the cipher
  456.   {$EXTERNALSYM KP_BLOCKLEN}
  457.   KP_KEYLEN           = 9; // Length of key in bits
  458.   {$EXTERNALSYM KP_KEYLEN}
  459.   KP_SALT_EX          = 10; // Length of salt in bytes
  460.   {$EXTERNALSYM KP_SALT_EX}
  461.   KP_P                = 11; // DSS/Diffie-Hellman P value
  462.   {$EXTERNALSYM KP_P}
  463.   KP_G                = 12; // DSS/Diffie-Hellman G value
  464.   {$EXTERNALSYM KP_G}
  465.   KP_Q                = 13; // DSS Q value
  466.   {$EXTERNALSYM KP_Q}
  467.   KP_X                = 14; // Diffie-Hellman X value
  468.   {$EXTERNALSYM KP_X}
  469.   KP_Y                = 15; // Y value
  470.   {$EXTERNALSYM KP_Y}
  471.   KP_RA               = 16; // Fortezza RA value
  472.   {$EXTERNALSYM KP_RA}
  473.   KP_RB               = 17; // Fortezza RB value
  474.   {$EXTERNALSYM KP_RB}
  475.   KP_INFO             = 18; // for putting information into an RSA envelope
  476.   {$EXTERNALSYM KP_INFO}
  477.   KP_EFFECTIVE_KEYLEN = 19; // setting and getting RC2 effective key length
  478.   {$EXTERNALSYM KP_EFFECTIVE_KEYLEN}
  479.   KP_SCHANNEL_ALG     = 20; // for setting the Secure Channel algorithms
  480.   {$EXTERNALSYM KP_SCHANNEL_ALG}
  481.   KP_CLIENT_RANDOM    = 21; // for setting the Secure Channel client random data
  482.   {$EXTERNALSYM KP_CLIENT_RANDOM}
  483.   KP_SERVER_RANDOM    = 22; // for setting the Secure Channel server random data
  484.   {$EXTERNALSYM KP_SERVER_RANDOM}
  485.   KP_RP               = 23;
  486.   {$EXTERNALSYM KP_RP}
  487.   KP_PRECOMP_MD5      = 24;
  488.   {$EXTERNALSYM KP_PRECOMP_MD5}
  489.   KP_PRECOMP_SHA      = 25;
  490.   {$EXTERNALSYM KP_PRECOMP_SHA}
  491.   KP_CERTIFICATE      = 26; // for setting Secure Channel certificate data (PCT1)
  492.   {$EXTERNALSYM KP_CERTIFICATE}
  493.   KP_CLEAR_KEY        = 27; // for setting Secure Channel clear key data (PCT1)
  494.   {$EXTERNALSYM KP_CLEAR_KEY}
  495.   KP_PUB_EX_LEN       = 28;
  496.   {$EXTERNALSYM KP_PUB_EX_LEN}
  497.   KP_PUB_EX_VAL       = 29;
  498.   {$EXTERNALSYM KP_PUB_EX_VAL}
  499.   KP_KEYVAL           = 30;
  500.   {$EXTERNALSYM KP_KEYVAL}
  501.   KP_ADMIN_PIN        = 31;
  502.   {$EXTERNALSYM KP_ADMIN_PIN}
  503.   KP_KEYEXCHANGE_PIN  = 32;
  504.   {$EXTERNALSYM KP_KEYEXCHANGE_PIN}
  505.   KP_SIGNATURE_PIN    = 33;
  506.   {$EXTERNALSYM KP_SIGNATURE_PIN}
  507.   KP_PREHASH          = 34;
  508.   {$EXTERNALSYM KP_PREHASH}
  509.   KP_OAEP_PARAMS     = 36; // for setting OAEP params on RSA keys
  510.   {$EXTERNALSYM KP_OAEP_PARAMS}
  511.   KP_CMS_KEY_INFO    = 37;
  512.   {$EXTERNALSYM KP_CMS_KEY_INFO}
  513.   KP_CMS_DH_KEY_INFO = 38;
  514.   {$EXTERNALSYM KP_CMS_DH_KEY_INFO}
  515.   KP_PUB_PARAMS      = 39; // for setting public parameters
  516.   {$EXTERNALSYM KP_PUB_PARAMS}
  517.   KP_VERIFY_PARAMS   = 40; // for verifying DSA and DH parameters
  518.   {$EXTERNALSYM KP_VERIFY_PARAMS}
  519.   KP_HIGHEST_VERSION = 41; // for TLS protocol version setting
  520.   {$EXTERNALSYM KP_HIGHEST_VERSION}
  521. // KP_PADDING
  522.   PKCS5_PADDING  = 1; // PKCS 5 (sec 6.2) padding method
  523.   {$EXTERNALSYM PKCS5_PADDING}
  524.   RANDOM_PADDING = 2;
  525.   {$EXTERNALSYM RANDOM_PADDING}
  526.   ZERO_PADDING   = 3;
  527.   {$EXTERNALSYM ZERO_PADDING}
  528. // KP_MODE
  529.   CRYPT_MODE_CBC = 1; // Cipher block chaining
  530.   {$EXTERNALSYM CRYPT_MODE_CBC}
  531.   CRYPT_MODE_ECB = 2; // Electronic code book
  532.   {$EXTERNALSYM CRYPT_MODE_ECB}
  533.   CRYPT_MODE_OFB = 3; // Output feedback mode
  534.   {$EXTERNALSYM CRYPT_MODE_OFB}
  535.   CRYPT_MODE_CFB = 4; // Cipher feedback mode
  536.   {$EXTERNALSYM CRYPT_MODE_CFB}
  537.   CRYPT_MODE_CTS = 5; // Ciphertext stealing mode
  538.   {$EXTERNALSYM CRYPT_MODE_CTS}
  539. // KP_PERMISSIONS
  540.   CRYPT_ENCRYPT    = $0001; // Allow encryption
  541.   {$EXTERNALSYM CRYPT_ENCRYPT}
  542.   CRYPT_DECRYPT    = $0002; // Allow decryption
  543.   {$EXTERNALSYM CRYPT_DECRYPT}
  544.   CRYPT_EXPORT     = $0004; // Allow key to be exported
  545.   {$EXTERNALSYM CRYPT_EXPORT}
  546.   CRYPT_READ       = $0008; // Allow parameters to be read
  547.   {$EXTERNALSYM CRYPT_READ}
  548.   CRYPT_WRITE      = $0010; // Allow parameters to be set
  549.   {$EXTERNALSYM CRYPT_WRITE}
  550.   CRYPT_MAC        = $0020; // Allow MACs to be used with key
  551.   {$EXTERNALSYM CRYPT_MAC}
  552.   CRYPT_EXPORT_KEY = $0040; // Allow key to be used for exporting keys
  553.   {$EXTERNALSYM CRYPT_EXPORT_KEY}
  554.   CRYPT_IMPORT_KEY = $0080; // Allow key to be used for importing keys
  555.   {$EXTERNALSYM CRYPT_IMPORT_KEY}
  556.   HP_ALGID         = $0001; // Hash algorithm
  557.   {$EXTERNALSYM HP_ALGID}
  558.   HP_HASHVAL       = $0002; // Hash value
  559.   {$EXTERNALSYM HP_HASHVAL}
  560.   HP_HASHSIZE      = $0004; // Hash value size
  561.   {$EXTERNALSYM HP_HASHSIZE}
  562.   HP_HMAC_INFO     = $0005; // information for creating an HMAC
  563.   {$EXTERNALSYM HP_HMAC_INFO}
  564.   HP_TLS1PRF_LABEL = $0006; // label for TLS1 PRF
  565.   {$EXTERNALSYM HP_TLS1PRF_LABEL}
  566.   HP_TLS1PRF_SEED  = $0007; // seed for TLS1 PRF
  567.   {$EXTERNALSYM HP_TLS1PRF_SEED}
  568.   CRYPT_FAILED  = FALSE;
  569.   {$EXTERNALSYM CRYPT_FAILED}
  570.   CRYPT_SUCCEED = TRUE;
  571.   {$EXTERNALSYM CRYPT_SUCCEED}
  572. function RCRYPT_SUCCEEDED(rt: BOOL): BOOL;
  573. {$EXTERNALSYM RCRYPT_SUCCEEDED}
  574. function RCRYPT_FAILED(rt: BOOL): BOOL;
  575. {$EXTERNALSYM RCRYPT_FAILED}
  576. //
  577. // CryptGetProvParam
  578. //
  579. const
  580.   PP_ENUMALGS            = 1;
  581.   {$EXTERNALSYM PP_ENUMALGS}
  582.   PP_ENUMCONTAINERS      = 2;
  583.   {$EXTERNALSYM PP_ENUMCONTAINERS}
  584.   PP_IMPTYPE             = 3;
  585.   {$EXTERNALSYM PP_IMPTYPE}
  586.   PP_NAME                = 4;
  587.   {$EXTERNALSYM PP_NAME}
  588.   PP_VERSION             = 5;
  589.   {$EXTERNALSYM PP_VERSION}
  590.   PP_CONTAINER           = 6;
  591.   {$EXTERNALSYM PP_CONTAINER}
  592.   PP_CHANGE_PASSWORD     = 7;
  593.   {$EXTERNALSYM PP_CHANGE_PASSWORD}
  594.   PP_KEYSET_SEC_DESCR    = 8; // get/set security descriptor of keyset
  595.   {$EXTERNALSYM PP_KEYSET_SEC_DESCR}
  596.   PP_CERTCHAIN           = 9; // for retrieving certificates from tokens
  597.   {$EXTERNALSYM PP_CERTCHAIN}
  598.   PP_KEY_TYPE_SUBTYPE    = 10;
  599.   {$EXTERNALSYM PP_KEY_TYPE_SUBTYPE}
  600.   PP_PROVTYPE            = 16;
  601.   {$EXTERNALSYM PP_PROVTYPE}
  602.   PP_KEYSTORAGE          = 17;
  603.   {$EXTERNALSYM PP_KEYSTORAGE}
  604.   PP_APPLI_CERT          = 18;
  605.   {$EXTERNALSYM PP_APPLI_CERT}
  606.   PP_SYM_KEYSIZE         = 19;
  607.   {$EXTERNALSYM PP_SYM_KEYSIZE}
  608.   PP_SESSION_KEYSIZE     = 20;
  609.   {$EXTERNALSYM PP_SESSION_KEYSIZE}
  610.   PP_UI_PROMPT           = 21;
  611.   {$EXTERNALSYM PP_UI_PROMPT}
  612.   PP_ENUMALGS_EX         = 22;
  613.   {$EXTERNALSYM PP_ENUMALGS_EX}
  614.   PP_ENUMMANDROOTS       = 25;
  615.   {$EXTERNALSYM PP_ENUMMANDROOTS}
  616.   PP_ENUMELECTROOTS      = 26;
  617.   {$EXTERNALSYM PP_ENUMELECTROOTS}
  618.   PP_KEYSET_TYPE         = 27;
  619.   {$EXTERNALSYM PP_KEYSET_TYPE}
  620.   PP_ADMIN_PIN           = 31;
  621.   {$EXTERNALSYM PP_ADMIN_PIN}
  622.   PP_KEYEXCHANGE_PIN     = 32;
  623.   {$EXTERNALSYM PP_KEYEXCHANGE_PIN}
  624.   PP_SIGNATURE_PIN       = 33;
  625.   {$EXTERNALSYM PP_SIGNATURE_PIN}
  626.   PP_SIG_KEYSIZE_INC     = 34;
  627.   {$EXTERNALSYM PP_SIG_KEYSIZE_INC}
  628.   PP_KEYX_KEYSIZE_INC    = 35;
  629.   {$EXTERNALSYM PP_KEYX_KEYSIZE_INC}
  630.   PP_UNIQUE_CONTAINER    = 36;
  631.   {$EXTERNALSYM PP_UNIQUE_CONTAINER}
  632.   PP_SGC_INFO            = 37;
  633.   {$EXTERNALSYM PP_SGC_INFO}
  634.   PP_USE_HARDWARE_RNG    = 38;
  635.   {$EXTERNALSYM PP_USE_HARDWARE_RNG}
  636.   PP_KEYSPEC             = 39;
  637.   {$EXTERNALSYM PP_KEYSPEC}
  638.   PP_ENUMEX_SIGNING_PROT = 40;
  639.   {$EXTERNALSYM PP_ENUMEX_SIGNING_PROT}
  640.   CRYPT_FIRST    = 1;
  641.   {$EXTERNALSYM CRYPT_FIRST}
  642.   CRYPT_NEXT     = 2;
  643.   {$EXTERNALSYM CRYPT_NEXT}
  644.   CRYPT_SGC_ENUM = 4;
  645.   {$EXTERNALSYM CRYPT_SGC_ENUM}
  646.   CRYPT_IMPL_HARDWARE  = 1;
  647.   {$EXTERNALSYM CRYPT_IMPL_HARDWARE}
  648.   CRYPT_IMPL_SOFTWARE  = 2;
  649.   {$EXTERNALSYM CRYPT_IMPL_SOFTWARE}
  650.   CRYPT_IMPL_MIXED     = 3;
  651.   {$EXTERNALSYM CRYPT_IMPL_MIXED}
  652.   CRYPT_IMPL_UNKNOWN   = 4;
  653.   {$EXTERNALSYM CRYPT_IMPL_UNKNOWN}
  654.   CRYPT_IMPL_REMOVABLE = 8;
  655.   {$EXTERNALSYM CRYPT_IMPL_REMOVABLE}
  656. // key storage flags
  657.   CRYPT_SEC_DESCR = $00000001;
  658.   {$EXTERNALSYM CRYPT_SEC_DESCR}
  659.   CRYPT_PSTORE    = $00000002;
  660.   {$EXTERNALSYM CRYPT_PSTORE}
  661.   CRYPT_UI_PROMPT = $00000004;
  662.   {$EXTERNALSYM CRYPT_UI_PROMPT}
  663. // protocol flags
  664.   CRYPT_FLAG_PCT1    = $0001;
  665.   {$EXTERNALSYM CRYPT_FLAG_PCT1}
  666.   CRYPT_FLAG_SSL2    = $0002;
  667.   {$EXTERNALSYM CRYPT_FLAG_SSL2}
  668.   CRYPT_FLAG_SSL3    = $0004;
  669.   {$EXTERNALSYM CRYPT_FLAG_SSL3}
  670.   CRYPT_FLAG_TLS1    = $0008;
  671.   {$EXTERNALSYM CRYPT_FLAG_TLS1}
  672.   CRYPT_FLAG_IPSEC   = $0010;
  673.   {$EXTERNALSYM CRYPT_FLAG_IPSEC}
  674.   CRYPT_FLAG_SIGNING = $0020;
  675.   {$EXTERNALSYM CRYPT_FLAG_SIGNING}
  676. // SGC flags
  677.   CRYPT_SGC     = $0001;
  678.   {$EXTERNALSYM CRYPT_SGC}
  679.   CRYPT_FASTSGC = $0002;
  680.   {$EXTERNALSYM CRYPT_FASTSGC}
  681. //
  682. // CryptSetProvParam
  683. //
  684.   PP_CLIENT_HWND         = 1;
  685.   {$EXTERNALSYM PP_CLIENT_HWND}
  686.   PP_CONTEXT_INFO        = 11;
  687.   {$EXTERNALSYM PP_CONTEXT_INFO}
  688.   PP_KEYEXCHANGE_KEYSIZE = 12;
  689.   {$EXTERNALSYM PP_KEYEXCHANGE_KEYSIZE}
  690.   PP_SIGNATURE_KEYSIZE   = 13;
  691.   {$EXTERNALSYM PP_SIGNATURE_KEYSIZE}
  692.   PP_KEYEXCHANGE_ALG     = 14;
  693.   {$EXTERNALSYM PP_KEYEXCHANGE_ALG}
  694.   PP_SIGNATURE_ALG       = 15;
  695.   {$EXTERNALSYM PP_SIGNATURE_ALG}
  696.   PP_DELETEKEY           = 24;
  697.   {$EXTERNALSYM PP_DELETEKEY}
  698.   PROV_RSA_FULL      = 1;
  699.   {$EXTERNALSYM PROV_RSA_FULL}
  700.   PROV_RSA_SIG       = 2;
  701.   {$EXTERNALSYM PROV_RSA_SIG}
  702.   PROV_DSS           = 3;
  703.   {$EXTERNALSYM PROV_DSS}
  704.   PROV_FORTEZZA      = 4;
  705.   {$EXTERNALSYM PROV_FORTEZZA}
  706.   PROV_MS_EXCHANGE   = 5;
  707.   {$EXTERNALSYM PROV_MS_EXCHANGE}
  708.   PROV_SSL           = 6;
  709.   {$EXTERNALSYM PROV_SSL}
  710.   PROV_RSA_SCHANNEL  = 12;
  711.   {$EXTERNALSYM PROV_RSA_SCHANNEL}
  712.   PROV_DSS_DH        = 13;
  713.   {$EXTERNALSYM PROV_DSS_DH}
  714.   PROV_EC_ECDSA_SIG  = 14;
  715.   {$EXTERNALSYM PROV_EC_ECDSA_SIG}
  716.   PROV_EC_ECNRA_SIG  = 15;
  717.   {$EXTERNALSYM PROV_EC_ECNRA_SIG}
  718.   PROV_EC_ECDSA_FULL = 16;
  719.   {$EXTERNALSYM PROV_EC_ECDSA_FULL}
  720.   PROV_EC_ECNRA_FULL = 17;
  721.   {$EXTERNALSYM PROV_EC_ECNRA_FULL}
  722.   PROV_DH_SCHANNEL   = 18;
  723.   {$EXTERNALSYM PROV_DH_SCHANNEL}
  724.   PROV_SPYRUS_LYNKS  = 20;
  725.   {$EXTERNALSYM PROV_SPYRUS_LYNKS}
  726.   PROV_RNG           = 21;
  727.   {$EXTERNALSYM PROV_RNG}
  728.   PROV_INTEL_SEC     = 22;
  729.   {$EXTERNALSYM PROV_INTEL_SEC}
  730. //
  731. // STT defined Providers
  732. //
  733.   PROV_STT_MER  = 7;
  734.   {$EXTERNALSYM PROV_STT_MER}
  735.   PROV_STT_ACQ  = 8;
  736.   {$EXTERNALSYM PROV_STT_ACQ}
  737.   PROV_STT_BRND = 9;
  738.   {$EXTERNALSYM PROV_STT_BRND}
  739.   PROV_STT_ROOT = 10;
  740.   {$EXTERNALSYM PROV_STT_ROOT}
  741.   PROV_STT_ISS  = 11;
  742.   {$EXTERNALSYM PROV_STT_ISS}
  743. //
  744. // Provider friendly names
  745. //
  746.   MS_DEF_PROV_A = 'Microsoft Base Cryptographic Provider v1.0';
  747.   {$EXTERNALSYM MS_DEF_PROV_A}
  748.   MS_DEF_PROV_W = 'Microsoft Base Cryptographic Provider v1.0';
  749.   {$EXTERNALSYM MS_DEF_PROV_W}
  750. {$IFDEF UNICODE}
  751.   MS_DEF_PROV = MS_DEF_PROV_W;
  752.   {$EXTERNALSYM MS_DEF_PROV}
  753. {$ELSE}
  754.   MS_DEF_PROV = MS_DEF_PROV_A;
  755.   {$EXTERNALSYM MS_DEF_PROV}
  756. {$ENDIF}
  757.   MS_ENHANCED_PROV_A = 'Microsoft Enhanced Cryptographic Provider v1.0';
  758.   {$EXTERNALSYM MS_ENHANCED_PROV_A}
  759.   MS_ENHANCED_PROV_W = 'Microsoft Enhanced Cryptographic Provider v1.0';
  760.   {$EXTERNALSYM MS_ENHANCED_PROV_W}
  761. {$IFDEF UNICODE}
  762.   MS_ENHANCED_PROV = MS_ENHANCED_PROV_W;
  763.   {$EXTERNALSYM MS_ENHANCED_PROV}
  764. {$ELSE}
  765.   MS_ENHANCED_PROV = MS_ENHANCED_PROV_A;
  766.   {$EXTERNALSYM MS_ENHANCED_PROV}
  767. {$ENDIF}
  768.   MS_STRONG_PROV_A = 'Microsoft Strong Cryptographic Provider';
  769.   {$EXTERNALSYM MS_STRONG_PROV_A}
  770.   MS_STRONG_PROV_W = 'Microsoft Strong Cryptographic Provider';
  771.   {$EXTERNALSYM MS_STRONG_PROV_W}
  772. {$IFDEF UNICODE}
  773.   MS_STRONG_PROV = MS_STRONG_PROV_W;
  774.   {$EXTERNALSYM MS_STRONG_PROV}
  775. {$ELSE}
  776.   MS_STRONG_PROV = MS_STRONG_PROV_A;
  777.   {$EXTERNALSYM MS_STRONG_PROV}
  778. {$ENDIF}
  779.   MS_DEF_RSA_SIG_PROV_A = 'Microsoft RSA Signature Cryptographic Provider';
  780.   {$EXTERNALSYM MS_DEF_RSA_SIG_PROV_A}
  781.   MS_DEF_RSA_SIG_PROV_W = 'Microsoft RSA Signature Cryptographic Provider';
  782.   {$EXTERNALSYM MS_DEF_RSA_SIG_PROV_W}
  783. {$IFDEF UNICODE}
  784.   MS_DEF_RSA_SIG_PROV = MS_DEF_RSA_SIG_PROV_W;
  785.   {$EXTERNALSYM MS_DEF_RSA_SIG_PROV}
  786. {$ELSE}
  787.   MS_DEF_RSA_SIG_PROV = MS_DEF_RSA_SIG_PROV_A;
  788.   {$EXTERNALSYM MS_DEF_RSA_SIG_PROV}
  789. {$ENDIF}
  790.   MS_DEF_RSA_SCHANNEL_PROV_A = 'Microsoft RSA SChannel Cryptographic Provider';
  791.   {$EXTERNALSYM MS_DEF_RSA_SCHANNEL_PROV_A}
  792.   MS_DEF_RSA_SCHANNEL_PROV_W = 'Microsoft RSA SChannel Cryptographic Provider';
  793.   {$EXTERNALSYM MS_DEF_RSA_SCHANNEL_PROV_W}
  794. {$IFDEF UNICODE}
  795.   MS_DEF_RSA_SCHANNEL_PROV = MS_DEF_RSA_SCHANNEL_PROV_W;
  796.   {$EXTERNALSYM MS_DEF_RSA_SCHANNEL_PROV}
  797. {$ELSE}
  798.   MS_DEF_RSA_SCHANNEL_PROV = MS_DEF_RSA_SCHANNEL_PROV_A;
  799.   {$EXTERNALSYM MS_DEF_RSA_SCHANNEL_PROV}
  800. {$ENDIF}
  801.   MS_DEF_DSS_PROV_A = 'Microsoft Base DSS Cryptographic Provider';
  802.   {$EXTERNALSYM MS_DEF_DSS_PROV_A}
  803.   MS_DEF_DSS_PROV_W = 'Microsoft Base DSS Cryptographic Provider';
  804.   {$EXTERNALSYM MS_DEF_DSS_PROV_W}
  805. {$IFDEF UNICODE}
  806.   MS_DEF_DSS_PROV = MS_DEF_DSS_PROV_W;
  807.   {$EXTERNALSYM MS_DEF_DSS_PROV}
  808. {$ELSE}
  809.   MS_DEF_DSS_PROV = MS_DEF_DSS_PROV_A;
  810.   {$EXTERNALSYM MS_DEF_DSS_PROV}
  811. {$ENDIF}
  812.   MS_DEF_DSS_DH_PROV_A = 'Microsoft Base DSS and Diffie-Hellman Cryptographic Provider';
  813.   {$EXTERNALSYM MS_DEF_DSS_DH_PROV_A}
  814.   MS_DEF_DSS_DH_PROV_W = 'Microsoft Base DSS and Diffie-Hellman Cryptographic Provider';
  815.   {$EXTERNALSYM MS_DEF_DSS_DH_PROV_W}
  816. {$IFDEF UNICODE}
  817.   MS_DEF_DSS_DH_PROV = MS_DEF_DSS_DH_PROV_W;
  818.   {$EXTERNALSYM MS_DEF_DSS_DH_PROV}
  819. {$ELSE}
  820.   MS_DEF_DSS_DH_PROV = MS_DEF_DSS_DH_PROV_A;
  821.   {$EXTERNALSYM MS_DEF_DSS_DH_PROV}
  822. {$ENDIF}
  823.   MS_ENH_DSS_DH_PROV_A = 'Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider';
  824.   {$EXTERNALSYM MS_ENH_DSS_DH_PROV_A}
  825.   MS_ENH_DSS_DH_PROV_W = 'Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider';
  826.   {$EXTERNALSYM MS_ENH_DSS_DH_PROV_W}
  827. {$IFDEF UNICODE}
  828.   MS_ENH_DSS_DH_PROV = MS_ENH_DSS_DH_PROV_W;
  829.   {$EXTERNALSYM MS_ENH_DSS_DH_PROV}
  830. {$ELSE}
  831.   MS_ENH_DSS_DH_PROV = MS_ENH_DSS_DH_PROV_A;
  832.   {$EXTERNALSYM MS_ENH_DSS_DH_PROV}
  833. {$ENDIF}
  834.   MS_DEF_DH_SCHANNEL_PROV_A = 'Microsoft DH SChannel Cryptographic Provider';
  835.   {$EXTERNALSYM MS_DEF_DH_SCHANNEL_PROV_A}
  836.   MS_DEF_DH_SCHANNEL_PROV_W = 'Microsoft DH SChannel Cryptographic Provider';
  837.   {$EXTERNALSYM MS_DEF_DH_SCHANNEL_PROV_W}
  838. {$IFDEF UNICODE}
  839.   MS_DEF_DH_SCHANNEL_PROV = MS_DEF_DH_SCHANNEL_PROV_W;
  840.   {$EXTERNALSYM MS_DEF_DH_SCHANNEL_PROV}
  841. {$ELSE}
  842.   MS_DEF_DH_SCHANNEL_PROV = MS_DEF_DH_SCHANNEL_PROV_A;
  843.   {$EXTERNALSYM MS_DEF_DH_SCHANNEL_PROV}
  844. {$ENDIF}
  845.   MS_SCARD_PROV_A = 'Microsoft Base Smart Card Crypto Provider';
  846.   {$EXTERNALSYM MS_SCARD_PROV_A}
  847.   MS_SCARD_PROV_W = 'Microsoft Base Smart Card Crypto Provider';
  848.   {$EXTERNALSYM MS_SCARD_PROV_W}
  849. {$IFDEF UNICODE}
  850.   MS_SCARD_PROV = MS_SCARD_PROV_W;
  851.   {$EXTERNALSYM MS_SCARD_PROV}
  852. {$ELSE}
  853.   MS_SCARD_PROV = MS_SCARD_PROV_A;
  854.   {$EXTERNALSYM MS_SCARD_PROV}
  855. {$ENDIF}
  856.   MAXUIDLEN = 64;
  857.   {$EXTERNALSYM MAXUIDLEN}
  858. // Exponentiation Offload Reg Location
  859.   EXPO_OFFLOAD_REG_VALUE = 'ExpoOffload';
  860.   {$EXTERNALSYM EXPO_OFFLOAD_REG_VALUE}
  861.   EXPO_OFFLOAD_FUNC_NAME = 'OffloadModExpo';
  862.   {$EXTERNALSYM EXPO_OFFLOAD_FUNC_NAME}
  863.   CUR_BLOB_VERSION = 2;
  864.   {$EXTERNALSYM CUR_BLOB_VERSION}
  865. // structure for use with CryptSetKeyParam for CMS keys
  866. // DO NOT USE THIS STRUCTURE!!!!!
  867. type
  868.   PCMS_KEY_INFO = ^CMS_KEY_INFO;
  869.   {$EXTERNALSYM PCMS_KEY_INFO}
  870.   _CMS_KEY_INFO = record
  871.     dwVersion: DWORD; // sizeof(CMS_KEY_INFO)
  872.     Algid: ALG_ID; // algorithmm id for the key to be converted
  873.     pbOID: LPBYTE; // pointer to OID to hash in with Z
  874.     cbOID: DWORD; // length of OID to hash in with Z
  875.   end;
  876.   {$EXTERNALSYM _CMS_KEY_INFO}
  877.   CMS_KEY_INFO = _CMS_KEY_INFO;
  878.   {$EXTERNALSYM CMS_KEY_INFO}
  879.   TCmsKeyInfo = CMS_KEY_INFO;
  880.   PCmsKeyInfo = PCMS_KEY_INFO;
  881. // structure for use with CryptSetHashParam with CALG_HMAC
  882.   PHMAC_Info = ^HMAC_Info;
  883.   {$EXTERNALSYM PHMAC_Info}
  884.   _HMAC_Info = record
  885.     HashAlgid: ALG_ID;
  886.     pbInnerString: LPBYTE;
  887.     cbInnerString: DWORD;
  888.     pbOuterString: LPBYTE;
  889.     cbOuterString: DWORD;
  890.   end;
  891.   {$EXTERNALSYM _HMAC_Info}
  892.   HMAC_Info = _HMAC_Info;
  893.   {$EXTERNALSYM HMAC_Info}
  894.   THMacInfo = HMAC_Info;
  895.   PHMacInfo = PHMAC_Info;
  896. // structure for use with CryptSetKeyParam with KP_SCHANNEL_ALG
  897.   PSCHANNEL_ALG = ^SCHANNEL_ALG;
  898.   {$EXTERNALSYM PSCHANNEL_ALG}
  899.   _SCHANNEL_ALG = record
  900.     dwUse: DWORD;
  901.     Algid: ALG_ID;
  902.     cBits: DWORD;
  903.     dwFlags: DWORD;
  904.     dwReserved: DWORD;
  905.   end;
  906.   {$EXTERNALSYM _SCHANNEL_ALG}
  907.   SCHANNEL_ALG = _SCHANNEL_ALG;
  908.   {$EXTERNALSYM SCHANNEL_ALG}
  909.   TSChannelAlg = SCHANNEL_ALG;
  910.   PSChannelAlg = PSCHANNEL_ALG;
  911. // uses of algortihms for SCHANNEL_ALG structure
  912. const
  913.   SCHANNEL_MAC_KEY = $00000000;
  914.   {$EXTERNALSYM SCHANNEL_MAC_KEY}
  915.   SCHANNEL_ENC_KEY = $00000001;
  916.   {$EXTERNALSYM SCHANNEL_ENC_KEY}
  917. // uses of dwFlags SCHANNEL_ALG structure
  918.   INTERNATIONAL_USAGE = $00000001;
  919.   {$EXTERNALSYM INTERNATIONAL_USAGE}
  920. type
  921.   PPROV_ENUMALGS = ^PROV_ENUMALGS;
  922.   {$NODEFINE PPROV_ENUMALGS}
  923.   _PROV_ENUMALGS = record
  924.     aiAlgid: ALG_ID;
  925.     dwBitLen: DWORD;
  926.     dwNameLen: DWORD;
  927.     szName: array [0..19] of CHAR;
  928.   end;
  929.   {$EXTERNALSYM _PROV_ENUMALGS}
  930.   PROV_ENUMALGS = _PROV_ENUMALGS;
  931.   {$EXTERNALSYM PROV_ENUMALGS}
  932.   TProvEnumAlgs = PROV_ENUMALGS;
  933.   PProvEnumAlgs = PPROV_ENUMALGS;
  934.   PPROV_ENUMALGS_EX = ^PROV_ENUMALGS_EX;
  935.   {$NODEFINE PPROV_ENUMALGS_EX}
  936.   _PROV_ENUMALGS_EX = record
  937.     aiAlgid: ALG_ID;
  938.     dwDefaultLen: DWORD;
  939.     dwMinLen: DWORD;
  940.     dwMaxLen: DWORD;
  941.     dwProtocols: DWORD;
  942.     dwNameLen: DWORD;
  943.     szName: array [0..19] of CHAR;
  944.     dwLongNameLen: DWORD;
  945.     szLongName: array [0..39] of CHAR;
  946.   end;
  947.   {$EXTERNALSYM _PROV_ENUMALGS_EX}
  948.   PROV_ENUMALGS_EX = _PROV_ENUMALGS_EX;
  949.   {$EXTERNALSYM PROV_ENUMALGS_EX}
  950.   TProvEnumAlgsEx = PROV_ENUMALGS_EX;
  951.   PProvEnumAlgsEx = PPROV_ENUMALGS_EX;
  952.   PPUBLICKEYSTRUC = ^PUBLICKEYSTRUC;
  953.   {$NODEFINE PPUBLICKEYSTRUC}
  954.   _PUBLICKEYSTRUC = record
  955.     bType: BYTE;
  956.     bVersion: BYTE;
  957.     reserved: WORD;
  958.     aiKeyAlg: ALG_ID;
  959.   end;
  960.   {$EXTERNALSYM _PUBLICKEYSTRUC}
  961.   PUBLICKEYSTRUC = _PUBLICKEYSTRUC;
  962.   {$EXTERNALSYM PUBLICKEYSTRUC}
  963.   BLOBHEADER = _PUBLICKEYSTRUC;
  964.   {$EXTERNALSYM BLOBHEADER}
  965.   TPublicKeyStruc = PUBLICKEYSTRUC;
  966.   PRSAPUBKEY = ^RSAPUBKEY;
  967.   {$NODEFINE PRSAPUBKEY}
  968.   _RSAPUBKEY = record
  969.     magic: DWORD; // Has to be RSA1
  970.     bitlen: DWORD; // # of bits in modulus
  971.     pubexp: DWORD; // public exponent
  972.     // Modulus data follows
  973.   end;
  974.   {$EXTERNALSYM _RSAPUBKEY}
  975.   RSAPUBKEY = _RSAPUBKEY;
  976.   {$EXTERNALSYM RSAPUBKEY}
  977.   TRsaPubKey = RSAPUBKEY;
  978.   _PUBKEY = record
  979.     magic: DWORD;
  980.     bitlen: DWORD; // # of bits in modulus
  981.   end;
  982.   {$EXTERNALSYM _PUBKEY}
  983.   DHPUBKEY = _PUBKEY;
  984.   {$EXTERNALSYM DHPUBKEY}
  985.   DSSPUBKEY = _PUBKEY;
  986.   {$EXTERNALSYM DSSPUBKEY}
  987.   KEAPUBKEY = _PUBKEY;
  988.   {$EXTERNALSYM KEAPUBKEY}
  989.   TEKPUBKEY = _PUBKEY;
  990.   {$EXTERNALSYM TEKPUBKEY}
  991.   PDSSSEED = ^DSSSEED;
  992.   {$NODEFINE PDSSSEED}
  993.   _DSSSEED = record
  994.     counter: DWORD;
  995.     seed: array [0..19] of BYTE;
  996.   end;
  997.   {$EXTERNALSYM _DSSSEED}
  998.   DSSSEED = _DSSSEED;
  999.   {$EXTERNALSYM DSSSEED}
  1000.   TDssSeed = DSSSEED;
  1001.   PPUBKEYVER3 = ^PUBKEYVER3;
  1002.   {$NODEFINE PPUBKEYVER3}
  1003.   _PUBKEYVER3 = record
  1004.     magic: DWORD;
  1005.     bitlenP: DWORD; // # of bits in prime modulus
  1006.     bitlenQ: DWORD; // # of bits in prime q, 0 if not available
  1007.     bitlenJ: DWORD; // # of bits in (p-1)/q, 0 if not available
  1008.     DSSSeed: DSSSEED;
  1009.   end;
  1010.   {$EXTERNALSYM _PUBKEYVER3}
  1011.   PUBKEYVER3 = _PUBKEYVER3;
  1012.   {$EXTERNALSYM PUBKEYVER3}
  1013.   DHPUBKEY_VER3 = PUBKEYVER3;
  1014.   {$EXTERNALSYM DHPUBKEY_VER3}
  1015.   TPubKeyVer3 = PUBKEYVER3;
  1016.   PPRIVKEYVER3 = ^DHPRIVKEY_VER3;
  1017.   {$NODEFINE PPRIVKEYVER3}
  1018.   _PRIVKEYVER3 = record
  1019.     magic: DWORD;
  1020.     bitlenP: DWORD; // # of bits in prime modulus
  1021.     bitlenQ: DWORD; // # of bits in prime q, 0 if not available
  1022.     bitlenJ: DWORD; // # of bits in (p-1)/q, 0 if not available
  1023.     bitlenX: DWORD; // # of bits in X
  1024.     DSSSeed: DSSSEED;
  1025.   end;
  1026.   {$EXTERNALSYM _PRIVKEYVER3}
  1027.   DHPRIVKEY_VER3 = _PRIVKEYVER3;
  1028.   {$EXTERNALSYM DHPRIVKEY_VER3}
  1029.   DSSPRIVKEY_VER3 = _PRIVKEYVER3;
  1030.   {$EXTERNALSYM DSSPRIVKEY_VER3}
  1031.   TDssPrivKey3 = DHPRIVKEY_VER3;
  1032.   PKEY_TYPE_SUBTYPE = ^KEY_TYPE_SUBTYPE;
  1033.   {$EXTERNALSYM PKEY_TYPE_SUBTYPE}
  1034.   _KEY_TYPE_SUBTYPE = record
  1035.     dwKeySpec: DWORD;
  1036.     Type_: GUID;
  1037.     Subtype: GUID;
  1038.   end;
  1039.   {$EXTERNALSYM _KEY_TYPE_SUBTYPE}
  1040.   KEY_TYPE_SUBTYPE = _KEY_TYPE_SUBTYPE;
  1041.   {$EXTERNALSYM KEY_TYPE_SUBTYPE}
  1042.   TKeyTypeSubType = KEY_TYPE_SUBTYPE;
  1043.   PKeyTypeSubType = PKEY_TYPE_SUBTYPE;
  1044.   PCERT_FORTEZZA_DATA_PROP = ^CERT_FORTEZZA_DATA_PROP;
  1045.   {$NODEFINE PCERT_FORTEZZA_DATA_PROP}
  1046.   _CERT_FORTEZZA_DATA_PROP = record
  1047.     SerialNumber: array [0..7] of Byte;
  1048.     CertIndex: Integer;
  1049.     CertLabel: array [0..35] of Byte;
  1050.   end;
  1051.   {$EXTERNALSYM _CERT_FORTEZZA_DATA_PROP}
  1052.   CERT_FORTEZZA_DATA_PROP = _CERT_FORTEZZA_DATA_PROP;
  1053.   {$EXTERNALSYM CERT_FORTEZZA_DATA_PROP}
  1054.   TCertFortezzaDataProp = CERT_FORTEZZA_DATA_PROP;
  1055.   PCertFortezzaDataProp = PCERT_FORTEZZA_DATA_PROP;
  1056. //+-------------------------------------------------------------------------
  1057. //  CRYPTOAPI BLOB definitions
  1058. //--------------------------------------------------------------------------
  1059. type
  1060.   _CRYPTOAPI_BLOB = record
  1061.     cbData: DWORD;
  1062.     pbData: LPBYTE;
  1063.   end;
  1064.   {$EXTERNALSYM _CRYPTOAPI_BLOB}
  1065.   CRYPT_INTEGER_BLOB = _CRYPTOAPI_BLOB;
  1066.   TCryptIntegerBlob = CRYPT_INTEGER_BLOB;
  1067.   {$EXTERNALSYM CRYPT_INTEGER_BLOB}
  1068.   PCRYPT_INTEGER_BLOB = ^_CRYPTOAPI_BLOB;
  1069.   {$EXTERNALSYM PCRYPT_INTEGER_BLOB}
  1070.   PCryptIntegerBlob = PCRYPT_INTEGER_BLOB;
  1071.   CRYPT_UINT_BLOB = _CRYPTOAPI_BLOB;
  1072.   {$EXTERNALSYM CRYPT_UINT_BLOB}
  1073.   TCryptUintBlob = CRYPT_UINT_BLOB;
  1074.   PCRYPT_UINT_BLOB = ^_CRYPTOAPI_BLOB;
  1075.   {$EXTERNALSYM PCRYPT_UINT_BLOB}
  1076.   PCryptUintBlob = PCRYPT_UINT_BLOB;
  1077.   CRYPT_OBJID_BLOB = _CRYPTOAPI_BLOB;
  1078.   {$EXTERNALSYM CRYPT_OBJID_BLOB}
  1079.   TCryptObjIdBlob = CRYPT_OBJID_BLOB;
  1080.   PCRYPT_OBJID_BLOB = ^_CRYPTOAPI_BLOB;
  1081.   {$EXTERNALSYM PCRYPT_OBJID_BLOB}
  1082.   PCryptObjIdBlob = PCRYPT_OBJID_BLOB;
  1083.   CERT_NAME_BLOB = _CRYPTOAPI_BLOB;
  1084.   {$EXTERNALSYM CERT_NAME_BLOB}
  1085.   TCertNameBlob = CERT_NAME_BLOB;
  1086.   PCERT_NAME_BLOB = ^_CRYPTOAPI_BLOB;
  1087.   {$EXTERNALSYM PCERT_NAME_BLOB}
  1088.   PCertNameBlob = PCERT_NAME_BLOB;
  1089.   CERT_RDN_VALUE_BLOB = _CRYPTOAPI_BLOB;
  1090.   {$EXTERNALSYM CERT_RDN_VALUE_BLOB}
  1091.   TCertRdnValueBlob = CERT_RDN_VALUE_BLOB;
  1092.   PCERT_RDN_VALUE_BLOB = ^_CRYPTOAPI_BLOB;
  1093.   {$EXTERNALSYM PCERT_RDN_VALUE_BLOB}
  1094.   PCertRdnValueBlob = PCERT_RDN_VALUE_BLOB;
  1095.   CERT_BLOB = _CRYPTOAPI_BLOB;
  1096.   {$EXTERNALSYM CERT_BLOB}
  1097.   TCertBlob = CERT_BLOB;
  1098.   PCERT_BLOB = ^_CRYPTOAPI_BLOB;
  1099.   {$EXTERNALSYM PCERT_BLOB}
  1100.   PCertBlob = PCERT_BLOB;
  1101.   CRL_BLOB = _CRYPTOAPI_BLOB;
  1102.   {$EXTERNALSYM CRL_BLOB}
  1103.   TCrlBlob = CRL_BLOB;
  1104.   PCRL_BLOB = ^_CRYPTOAPI_BLOB;
  1105.   {$EXTERNALSYM PCRL_BLOB}
  1106.   PCrlBlob = PCRL_BLOB;
  1107.   DATA_BLOB = _CRYPTOAPI_BLOB;
  1108.   {$EXTERNALSYM DATA_BLOB}
  1109.   TDataBlob = DATA_BLOB;
  1110.   PDATA_BLOB = ^_CRYPTOAPI_BLOB;
  1111.   {$EXTERNALSYM PDATA_BLOB}
  1112.   PDataBlob = PDATA_BLOB;
  1113.   CRYPT_DATA_BLOB = _CRYPTOAPI_BLOB;
  1114.   {$EXTERNALSYM CRYPT_DATA_BLOB}
  1115.   TCryptDataBlob = CRYPT_DATA_BLOB;
  1116.   PCRYPT_DATA_BLOB = ^_CRYPTOAPI_BLOB;
  1117.   {$EXTERNALSYM PCRYPT_DATA_BLOB}
  1118.   PCryptDataBlob = PCRYPT_DATA_BLOB;
  1119.   CRYPT_HASH_BLOB = _CRYPTOAPI_BLOB;
  1120.   {$EXTERNALSYM CRYPT_HASH_BLOB}
  1121.   TCryptHashBlob = CRYPT_HASH_BLOB;
  1122.   PCRYPT_HASH_BLOB = ^_CRYPTOAPI_BLOB;
  1123.   {$EXTERNALSYM PCRYPT_HASH_BLOB}
  1124.   PCryptHashBlob = PCRYPT_HASH_BLOB;
  1125.   CRYPT_DIGEST_BLOB = _CRYPTOAPI_BLOB;
  1126.   {$EXTERNALSYM CRYPT_DIGEST_BLOB}
  1127.   TCryptDigestBlob = CRYPT_DIGEST_BLOB;
  1128.   PCRYPT_DIGEST_BLOB = ^_CRYPTOAPI_BLOB;
  1129.   {$EXTERNALSYM PCRYPT_DIGEST_BLOB}
  1130.   PCryptDigestBlob = PCRYPT_DIGEST_BLOB;
  1131.   CRYPT_DER_BLOB = _CRYPTOAPI_BLOB;
  1132.   {$EXTERNALSYM CRYPT_DER_BLOB}
  1133.   TCyptDerBlob = CRYPT_DER_BLOB;
  1134.   PCRYPT_DER_BLOB = ^_CRYPTOAPI_BLOB;
  1135.   {$EXTERNALSYM PCRYPT_DER_BLOB}
  1136.   PCyptDerBlob = PCRYPT_DER_BLOB;
  1137.   CRYPT_ATTR_BLOB = _CRYPTOAPI_BLOB;
  1138.   {$EXTERNALSYM CRYPT_ATTR_BLOB}
  1139.   TCryptAttrBlob = CRYPT_ATTR_BLOB;
  1140.   PCRYPT_ATTR_BLOB = ^_CRYPTOAPI_BLOB;
  1141.   {$EXTERNALSYM PCRYPT_ATTR_BLOB}
  1142.   PCryptAttrBlob = PCRYPT_ATTR_BLOB;  
  1143. // structure for use with CryptSetKeyParam for CMS keys
  1144.   PCMS_DH_KEY_INFO = ^CMS_DH_KEY_INFO;
  1145.   {$EXTERNALSYM PCMS_DH_KEY_INFO}
  1146.   _CMS_DH_KEY_INFO = record
  1147.     dwVersion: DWORD; // sizeof(CMS_DH_KEY_INFO)
  1148.     Algid: ALG_ID; // algorithmm id for the key to be converted
  1149.     pszContentEncObjId: LPSTR; // pointer to OID to hash in with Z
  1150.     PubInfo: CRYPT_DATA_BLOB; // OPTIONAL - public information
  1151.     pReserved: Pointer; // reserved - should be NULL
  1152.   end;
  1153.   {$EXTERNALSYM _CMS_DH_KEY_INFO}
  1154.   CMS_DH_KEY_INFO = _CMS_DH_KEY_INFO;
  1155.   {$EXTERNALSYM CMS_DH_KEY_INFO}
  1156.   TCmsDhKeyInfo = CMS_DH_KEY_INFO;
  1157.   PCmsDhKeyInfo = PCMS_DH_KEY_INFO;
  1158. function CryptAcquireContextA(var phProv: HCRYPTPROV; pszContainer: LPCSTR;
  1159.   pszProvider: LPCSTR; dwProvType: DWORD; dwFlags: DWORD): BOOL; stdcall;
  1160. {$EXTERNALSYM CryptAcquireContextA}
  1161. function CryptAcquireContextW(var phProv: HCRYPTPROV; pszContainer: LPCWSTR;
  1162.   pszProvider: LPCWSTR; dwProvType: DWORD; dwFlags: DWORD): BOOL; stdcall;
  1163. {$EXTERNALSYM CryptAcquireContextW}
  1164. {$IFDEF UNICODE}
  1165. function CryptAcquireContext(var phProv: HCRYPTPROV; pszContainer: LPCWSTR;
  1166.   pszProvider: LPCWSTR; dwProvType: DWORD; dwFlags: DWORD): BOOL; stdcall;
  1167. {$EXTERNALSYM CryptAcquireContext}
  1168. {$ELSE}
  1169. function CryptAcquireContext(var phProv: HCRYPTPROV; pszContainer: LPCSTR;
  1170.   pszProvider: LPCSTR; dwProvType: DWORD; dwFlags: DWORD): BOOL; stdcall;
  1171. {$EXTERNALSYM CryptAcquireContext}
  1172. {$ENDIF}
  1173. function CryptReleaseContext(hProv: HCRYPTPROV; dwFlags: ULONG_PTR): BOOL; stdcall;
  1174. {$EXTERNALSYM CryptReleaseContext}
  1175. function CryptGenKey(hProv: HCRYPTPROV; Algid: ALG_ID; dwFlags: DWORD;
  1176.   var phKey: HCRYPTKEY): BOOL; stdcall;
  1177. {$EXTERNALSYM CryptGenKey}
  1178. function CryptDeriveKey(hProv: HCRYPTPROV; Algid: ALG_ID; hBaseData: HCRYPTHASH;
  1179.   dwFlags: DWORD; var phKey: HCRYPTKEY): BOOL; stdcall;
  1180. {$EXTERNALSYM CryptDeriveKey}
  1181. function CryptDestroyKey(hKey: HCRYPTKEY): BOOL; stdcall;
  1182. {$EXTERNALSYM CryptDestroyKey}
  1183. function CryptSetKeyParam(hKey: HCRYPTKEY; dwParam: DWORD; pbData: LPBYTE;
  1184.   dwFlags: DWORD): BOOL; stdcall;
  1185. {$EXTERNALSYM CryptSetKeyParam}
  1186. function CryptGetKeyParam(hKey: HCRYPTKEY; dwParam: DWORD; pbData: LPBYTE;
  1187.   var pdwDataLen: DWORD; dwFlags: DWORD): BOOL; stdcall;
  1188. {$EXTERNALSYM CryptGetKeyParam}
  1189. function CryptSetHashParam(hHash: HCRYPTHASH; dwParam: DWORD; pbData: LPBYTE;
  1190.   dwFlags: DWORD): BOOL; stdcall;
  1191. {$EXTERNALSYM CryptSetHashParam}
  1192. function CryptGetHashParam(hHash: HCRYPTHASH; dwParam: DWORD; pbData: LPBYTE;
  1193.   var pdwDataLen: DWORD; dwFlags: DWORD): BOOL; stdcall;
  1194. {$EXTERNALSYM CryptGetHashParam}
  1195. function CryptSetProvParam(hProv: HCRYPTPROV; dwParam: DWORD; pbData: LPBYTE;
  1196.   dwFlags: DWORD): BOOL; stdcall;
  1197. {$EXTERNALSYM CryptSetProvParam}
  1198. function CryptGetProvParam(hProv: HCRYPTPROV; dwParam: DWORD; pbData: LPBYTE;
  1199.   var pdwDataLen: DWORD; dwFlags: DWORD): BOOL; stdcall;
  1200. {$EXTERNALSYM CryptGetProvParam}
  1201. function CryptGenRandom(hProv: HCRYPTPROV; dwLen: DWORD; pbBuffer: LPBYTE): BOOL; stdcall;
  1202. {$EXTERNALSYM CryptGenRandom}
  1203. function CryptGetUserKey(hProv: HCRYPTPROV; dwKeySpec: DWORD; var phUserKey: HCRYPTKEY): BOOL; stdcall;
  1204. {$EXTERNALSYM CryptGetUserKey}
  1205. function CryptExportKey(hKey, hExpKey: HCRYPTKEY; dwBlobType, dwFlags: DWORD;
  1206.   pbData: LPBYTE; var pdwDataLen: DWORD): BOOL; stdcall;
  1207. {$EXTERNALSYM CryptExportKey}
  1208. function CryptImportKey(hProv: HCRYPTPROV; pbData: LPBYTE; dwDataLen: DWORD;
  1209.   hPubKey: HCRYPTKEY; dwFlags: DWORD; var phKey: HCRYPTKEY): BOOL; stdcall;
  1210. {$EXTERNALSYM CryptImportKey}
  1211. function CryptEncrypt(hKey: HCRYPTKEY; hHash: HCRYPTHASH; Final: BOOL;
  1212.   dwFlags: DWORD; pbData: LPBYTE; var pdwDataLen: DWORD; dwBufLen: DWORD): BOOL; stdcall;
  1213. {$EXTERNALSYM CryptEncrypt}
  1214. function CryptDecrypt(hKey: HCRYPTKEY; hHash: HCRYPTHASH; Final: BOOL;
  1215.   dwFlags: DWORD; pbData: LPBYTE; var pdwDataLen: DWORD): BOOL; stdcall;
  1216. {$EXTERNALSYM CryptDecrypt}
  1217. function CryptCreateHash(hProv: HCRYPTPROV; Algid: ALG_ID; hKey: HCRYPTKEY;
  1218.   dwFlags: DWORD; var phHash: HCRYPTHASH): BOOL; stdcall;
  1219. {$EXTERNALSYM CryptCreateHash}
  1220. function CryptHashData(hHash: HCRYPTHASH; pbData: LPBYTE; dwDataLen, dwFlags: DWORD): BOOL; stdcall;
  1221. {$EXTERNALSYM CryptHashData}
  1222. function CryptHashSessionKey(hHash: HCRYPTHASH; hKey: HCRYPTKEY; dwFlags: DWORD): BOOL; stdcall;
  1223. {$EXTERNALSYM CryptHashSessionKey}
  1224. function CryptDestroyHash(hHash: HCRYPTHASH): BOOL; stdcall;
  1225. {$EXTERNALSYM CryptDestroyHash}
  1226. function CryptSignHashA(hHash: HCRYPTHASH; dwKeySpec: DWORD; sDescription: LPCSTR;
  1227.   dwFlags: DWORD; pbSignature: LPBYTE; var pdwSigLen: DWORD): BOOL; stdcall;
  1228. {$EXTERNALSYM CryptSignHashA}
  1229. function CryptSignHashW(hHash: HCRYPTHASH; dwKeySpec: DWORD; sDescription: LPCWSTR;
  1230.   dwFlags: DWORD; pbSignature: LPBYTE; var pdwSigLen: DWORD): BOOL; stdcall;
  1231. {$EXTERNALSYM CryptSignHashW}
  1232. {$IFDEF UNICODE}
  1233. function CryptSignHash(hHash: HCRYPTHASH; dwKeySpec: DWORD; sDescription: LPCWSTR;
  1234.   dwFlags: DWORD; pbSignature: LPBYTE; var pdwSigLen: DWORD): BOOL; stdcall;
  1235. {$EXTERNALSYM CryptSignHash}
  1236. {$ELSE}
  1237. function CryptSignHash(hHash: HCRYPTHASH; dwKeySpec: DWORD; sDescription: LPCSTR;
  1238.   dwFlags: DWORD; pbSignature: LPBYTE; var pdwSigLen: DWORD): BOOL; stdcall;
  1239. {$EXTERNALSYM CryptSignHash}
  1240. {$ENDIF}
  1241. function CryptVerifySignatureA(hHash: HCRYPTHASH; pbSignature: LPBYTE;
  1242.   dwSigLen: DWORD; hPubKey: HCRYPTKEY; sDescription: LPCSTR; dwFlags: DWORD): BOOL; stdcall;
  1243. {$EXTERNALSYM CryptVerifySignatureA}
  1244. function CryptVerifySignatureW(hHash: HCRYPTHASH; pbSignature: LPBYTE;
  1245.   dwSigLen: DWORD; hPubKey: HCRYPTKEY; sDescription: LPCWSTR; dwFlags: DWORD): BOOL; stdcall;
  1246. {$EXTERNALSYM CryptVerifySignatureW}
  1247. {$IFDEF UNICODE}
  1248. function CryptVerifySignature(hHash: HCRYPTHASH; pbSignature: LPBYTE;
  1249.   dwSigLen: DWORD; hPubKey: HCRYPTKEY; sDescription: LPCWSTR; dwFlags: DWORD): BOOL; stdcall;
  1250. {$EXTERNALSYM CryptVerifySignature}
  1251. {$ELSE}
  1252. function CryptVerifySignature(hHash: HCRYPTHASH; pbSignature: LPBYTE;
  1253.   dwSigLen: DWORD; hPubKey: HCRYPTKEY; sDescription: LPCSTR; dwFlags: DWORD): BOOL; stdcall;
  1254. {$EXTERNALSYM CryptVerifySignature}
  1255. {$ENDIF}
  1256. function CryptSetProviderA(pszProvName: LPCSTR; dwProvType: DWORD): BOOL; stdcall;
  1257. {$EXTERNALSYM CryptSetProviderA}
  1258. function CryptSetProviderW(pszProvName: LPCWSTR; dwProvType: DWORD): BOOL; stdcall;
  1259. {$EXTERNALSYM CryptSetProviderW}
  1260. {$IFDEF UNICODE}
  1261. function CryptSetProvider(pszProvName: LPCWSTR; dwProvType: DWORD): BOOL; stdcall;
  1262. {$EXTERNALSYM CryptSetProvider}
  1263. {$ELSE}
  1264. function CryptSetProvider(pszProvName: LPCSTR; dwProvType: DWORD): BOOL; stdcall;
  1265. {$EXTERNALSYM CryptSetProvider}
  1266. {$ENDIF}
  1267. function CryptSetProviderExA(pszProvName: LPCSTR; dwProvType: DWORD;
  1268.   pdwReserved: LPDWORD; dwFlags: DWORD): BOOL; stdcall;
  1269. {$EXTERNALSYM CryptSetProviderExA}
  1270. function CryptSetProviderExW(pszProvName: LPCWSTR; dwProvType: DWORD;
  1271.   pdwReserved: LPDWORD; dwFlags: DWORD): BOOL; stdcall;
  1272. {$EXTERNALSYM CryptSetProviderExW}
  1273. {$IFDEF UNICODE}
  1274. function CryptSetProviderEx(pszProvName: LPCWSTR; dwProvType: DWORD;
  1275.   pdwReserved: LPDWORD; dwFlags: DWORD): BOOL; stdcall;
  1276. {$EXTERNALSYM CryptSetProviderEx}
  1277. {$ELSE}
  1278. function CryptSetProviderEx(pszProvName: LPCSTR; dwProvType: DWORD;
  1279.   pdwReserved: LPDWORD; dwFlags: DWORD): BOOL; stdcall;
  1280. {$EXTERNALSYM CryptSetProviderEx}
  1281. {$ENDIF}
  1282. function CryptGetDefaultProviderA(dwProvType: DWORD; pdwReserved: LPDWORD;
  1283.   dwFlags: DWORD; pszProvName: LPSTR; var pcbProvName: DWORD): BOOL; stdcall;
  1284. {$EXTERNALSYM CryptGetDefaultProviderA}
  1285. function CryptGetDefaultProviderW(dwProvType: DWORD; pdwReserved: LPDWORD;
  1286.   dwFlags: DWORD; pszProvName: LPWSTR; var pcbProvName: DWORD): BOOL; stdcall;
  1287. {$EXTERNALSYM CryptGetDefaultProviderW}
  1288. {$IFDEF UNICODE}
  1289. function CryptGetDefaultProvider(dwProvType: DWORD; pdwReserved: LPDWORD;
  1290.   dwFlags: DWORD; pszProvName: LPWSTR; var pcbProvName: DWORD): BOOL; stdcall;
  1291. {$EXTERNALSYM CryptGetDefaultProvider}
  1292. {$ELSE}
  1293. function CryptGetDefaultProvider(dwProvType: DWORD; pdwReserved: LPDWORD;
  1294.   dwFlags: DWORD; pszProvName: LPSTR; var pcbProvName: DWORD): BOOL; stdcall;
  1295. {$EXTERNALSYM CryptGetDefaultProvider}
  1296. {$ENDIF}
  1297. function CryptEnumProviderTypesA(dwIndex: DWORD; pdwReserved: LPDWORD;
  1298.   dwFlags: DWORD; var pdwProvType: DWORD; pszTypeName: LPSTR;
  1299.   var pcbTypeName: DWORD): BOOL; stdcall;
  1300. {$EXTERNALSYM CryptEnumProviderTypesA}
  1301. function CryptEnumProviderTypesW(dwIndex: DWORD; pdwReserved: LPDWORD;
  1302.   dwFlags: DWORD; var pdwProvType: DWORD; pszTypeName: LPWSTR;
  1303.   var pcbTypeName: DWORD): BOOL; stdcall;
  1304. {$EXTERNALSYM CryptEnumProviderTypesW}
  1305. {$IFDEF UNICODE}
  1306. function CryptEnumProviderTypes(dwIndex: DWORD; pdwReserved: LPDWORD;
  1307.   dwFlags: DWORD; var pdwProvType: DWORD; pszTypeName: LPWSTR;
  1308.   var pcbTypeName: DWORD): BOOL; stdcall;
  1309. {$EXTERNALSYM CryptEnumProviderTypes}
  1310. {$ELSE}
  1311. function CryptEnumProviderTypes(dwIndex: DWORD; pdwReserved: LPDWORD;
  1312.   dwFlags: DWORD; var pdwProvType: DWORD; pszTypeName: LPSTR;
  1313.   var pcbTypeName: DWORD): BOOL; stdcall;
  1314. {$EXTERNALSYM CryptEnumProviderTypes}
  1315. {$ENDIF}
  1316. function CryptEnumProvidersA(dwIndex: DWORD; pdwReserved: LPDWORD; dwFlags: DWORD;
  1317.   var pdwProvType: DWORD; pszProvName: LPSTR; var pcbProvName: DWORD): BOOL; stdcall;
  1318. {$EXTERNALSYM CryptEnumProvidersA}
  1319. function CryptEnumProvidersW(dwIndex: DWORD; pdwReserved: LPDWORD; dwFlags: DWORD;
  1320.   var pdwProvType: DWORD; pszProvName: LPWSTR; var pcbProvName: DWORD): BOOL; stdcall;
  1321. {$EXTERNALSYM CryptEnumProvidersW}
  1322. {$IFDEF UNICODE}
  1323. function CryptEnumProviders(dwIndex: DWORD; pdwReserved: LPDWORD; dwFlags: DWORD;
  1324.   var pdwProvType: DWORD; pszProvName: LPWSTR; var pcbProvName: DWORD): BOOL; stdcall;
  1325. {$EXTERNALSYM CryptEnumProviders}
  1326. {$ELSE}
  1327. function CryptEnumProviders(dwIndex: DWORD; pdwReserved: LPDWORD; dwFlags: DWORD;
  1328.   var pdwProvType: DWORD; pszProvName: LPSTR; var pcbProvName: DWORD): BOOL; stdcall;
  1329. {$EXTERNALSYM CryptEnumProviders}
  1330. {$ENDIF}
  1331. function CryptContextAddRef(hProv: HCRYPTPROV; pdwReserved: LPDWORD; dwFlags: DWORD): BOOL; stdcall;
  1332. {$EXTERNALSYM CryptContextAddRef}
  1333. function CryptDuplicateKey(hKey: HCRYPTKEY; pdwReserved: LPDWORD; dwFlags: DWORD;
  1334.   var phKey: HCRYPTKEY): BOOL; stdcall;
  1335. {$EXTERNALSYM CryptDuplicateKey}
  1336. function CryptDuplicateHash(hHash: HCRYPTHASH; pdwReserved: LPDWORD;
  1337.   dwFlags: DWORD; var phHash: HCRYPTHASH): BOOL; stdcall;
  1338. {$EXTERNALSYM CryptDuplicateHash}
  1339. //+-------------------------------------------------------------------------
  1340. //  In a CRYPT_BIT_BLOB the last byte may contain 0-7 unused bits. Therefore, the
  1341. //  overall bit length is cbData * 8 - cUnusedBits.
  1342. //--------------------------------------------------------------------------
  1343. type
  1344.   PCRYPT_BIT_BLOB = ^CRYPT_BIT_BLOB;
  1345.   {$EXTERNALSYM PCRYPT_BIT_BLOB}
  1346.   _CRYPT_BIT_BLOB = record
  1347.     cbData: DWORD;
  1348.     pbData: LPBYTE;
  1349.     cUnusedBits: DWORD;
  1350.   end;
  1351.   {$EXTERNALSYM _CRYPT_BIT_BLOB}
  1352.   CRYPT_BIT_BLOB = _CRYPT_BIT_BLOB;
  1353.   {$EXTERNALSYM CRYPT_BIT_BLOB}
  1354.   TCryptBitBlob = CRYPT_BIT_BLOB;
  1355.   PCryptBitBlob = PCRYPT_BIT_BLOB;
  1356. //+-------------------------------------------------------------------------
  1357. //  Type used for any algorithm
  1358. //
  1359. //  Where the Parameters CRYPT_OBJID_BLOB is in its encoded representation. For most
  1360. //  algorithm types, the Parameters CRYPT_OBJID_BLOB is NULL (Parameters.cbData = 0).
  1361. //--------------------------------------------------------------------------
  1362. type
  1363.   PCRYPT_ALGORITHM_IDENTIFIER = ^CRYPT_ALGORITHM_IDENTIFIER;
  1364.   {$EXTERNALSYM PCRYPT_ALGORITHM_IDENTIFIER}
  1365.   _CRYPT_ALGORITHM_IDENTIFIER = record
  1366.     pszObjId: LPSTR;
  1367.     Parameters: CRYPT_OBJID_BLOB;
  1368.   end;
  1369.   {$EXTERNALSYM _CRYPT_ALGORITHM_IDENTIFIER}
  1370.   CRYPT_ALGORITHM_IDENTIFIER = _CRYPT_ALGORITHM_IDENTIFIER;
  1371.   {$EXTERNALSYM CRYPT_ALGORITHM_IDENTIFIER}
  1372.   TCryptAlgorithmIdentifier = CRYPT_ALGORITHM_IDENTIFIER;
  1373.   PCryptAlgorithmIdentifier = PCRYPT_ALGORITHM_IDENTIFIER;
  1374. // Following are the definitions of various algorithm object identifiers
  1375. // RSA
  1376. const
  1377.   szOID_RSA         = '1.2.840.113549';
  1378.   {$EXTERNALSYM szOID_RSA}
  1379.   szOID_PKCS        = '1.2.840.113549.1';
  1380.   {$EXTERNALSYM szOID_PKCS}
  1381.   szOID_RSA_HASH    = '1.2.840.113549.2';
  1382.   {$EXTERNALSYM szOID_RSA_HASH}
  1383.   szOID_RSA_ENCRYPT = '1.2.840.113549.3';
  1384.   {$EXTERNALSYM szOID_RSA_ENCRYPT}
  1385.   szOID_PKCS_1  = '1.2.840.113549.1.1';
  1386.   {$EXTERNALSYM szOID_PKCS_1}
  1387.   szOID_PKCS_2  = '1.2.840.113549.1.2';
  1388.   {$EXTERNALSYM szOID_PKCS_2}
  1389.   szOID_PKCS_3  = '1.2.840.113549.1.3';
  1390.   {$EXTERNALSYM szOID_PKCS_3}
  1391.   szOID_PKCS_4  = '1.2.840.113549.1.4';
  1392.   {$EXTERNALSYM szOID_PKCS_4}
  1393.   szOID_PKCS_5  = '1.2.840.113549.1.5';
  1394.   {$EXTERNALSYM szOID_PKCS_5}
  1395.   szOID_PKCS_6  = '1.2.840.113549.1.6';
  1396.   {$EXTERNALSYM szOID_PKCS_6}
  1397.   szOID_PKCS_7  = '1.2.840.113549.1.7';
  1398.   {$EXTERNALSYM szOID_PKCS_7}
  1399.   szOID_PKCS_8  = '1.2.840.113549.1.8';
  1400.   {$EXTERNALSYM szOID_PKCS_8}
  1401.   szOID_PKCS_9  = '1.2.840.113549.1.9';
  1402.   {$EXTERNALSYM szOID_PKCS_9}
  1403.   szOID_PKCS_10 = '1.2.840.113549.1.10';
  1404.   {$EXTERNALSYM szOID_PKCS_10}
  1405.   szOID_PKCS_12 = '1.2.840.113549.1.12';
  1406.   {$EXTERNALSYM szOID_PKCS_12}
  1407.   szOID_RSA_RSA         = '1.2.840.113549.1.1.1';
  1408.   {$EXTERNALSYM szOID_RSA_RSA}
  1409.   szOID_RSA_MD2RSA      = '1.2.840.113549.1.1.2';
  1410.   {$EXTERNALSYM szOID_RSA_MD2RSA}
  1411.   szOID_RSA_MD4RSA      = '1.2.840.113549.1.1.3';
  1412.   {$EXTERNALSYM szOID_RSA_MD4RSA}
  1413.   szOID_RSA_MD5RSA      = '1.2.840.113549.1.1.4';
  1414.   {$EXTERNALSYM szOID_RSA_MD5RSA}
  1415.   szOID_RSA_SHA1RSA     = '1.2.840.113549.1.1.5';
  1416.   {$EXTERNALSYM szOID_RSA_SHA1RSA}
  1417.   szOID_RSA_SETOAEP_RSA = '1.2.840.113549.1.1.6';
  1418.   {$EXTERNALSYM szOID_RSA_SETOAEP_RSA}
  1419.   szOID_RSA_DH = '1.2.840.113549.1.3.1';
  1420.   {$EXTERNALSYM szOID_RSA_DH}
  1421.   szOID_RSA_data          = '1.2.840.113549.1.7.1';
  1422.   {$EXTERNALSYM szOID_RSA_data}
  1423.   szOID_RSA_signedData    = '1.2.840.113549.1.7.2';
  1424.   {$EXTERNALSYM szOID_RSA_signedData}
  1425.   szOID_RSA_envelopedData = '1.2.840.113549.1.7.3';
  1426.   {$EXTERNALSYM szOID_RSA_envelopedData}
  1427.   szOID_RSA_signEnvData   = '1.2.840.113549.1.7.4';
  1428.   {$EXTERNALSYM szOID_RSA_signEnvData}
  1429.   szOID_RSA_digestedData  = '1.2.840.113549.1.7.5';
  1430.   {$EXTERNALSYM szOID_RSA_digestedData}
  1431.   szOID_RSA_hashedData    = '1.2.840.113549.1.7.5';
  1432.   {$EXTERNALSYM szOID_RSA_hashedData}
  1433.   szOID_RSA_encryptedData = '1.2.840.113549.1.7.6';
  1434.   {$EXTERNALSYM szOID_RSA_encryptedData}
  1435.   szOID_RSA_emailAddr         = '1.2.840.113549.1.9.1';
  1436.   {$EXTERNALSYM szOID_RSA_emailAddr}
  1437.   szOID_RSA_unstructName      = '1.2.840.113549.1.9.2';
  1438.   {$EXTERNALSYM szOID_RSA_unstructName}
  1439.   szOID_RSA_contentType       = '1.2.840.113549.1.9.3';
  1440.   {$EXTERNALSYM szOID_RSA_contentType}
  1441.   szOID_RSA_messageDigest     = '1.2.840.113549.1.9.4';
  1442.   {$EXTERNALSYM szOID_RSA_messageDigest}
  1443.   szOID_RSA_signingTime       = '1.2.840.113549.1.9.5';
  1444.   {$EXTERNALSYM szOID_RSA_signingTime}
  1445.   szOID_RSA_counterSign       = '1.2.840.113549.1.9.6';
  1446.   {$EXTERNALSYM szOID_RSA_counterSign}
  1447.   szOID_RSA_challengePwd      = '1.2.840.113549.1.9.7';
  1448.   {$EXTERNALSYM szOID_RSA_challengePwd}
  1449.   szOID_RSA_unstructAddr      = '1.2.840.113549.1.9.8';
  1450.   {$EXTERNALSYM szOID_RSA_unstructAddr}
  1451.   szOID_RSA_extCertAttrs      = '1.2.840.113549.1.9.9';
  1452.   {$EXTERNALSYM szOID_RSA_extCertAttrs}
  1453.   szOID_RSA_certExtensions    = '1.2.840.113549.1.9.14';
  1454.   {$EXTERNALSYM szOID_RSA_certExtensions}
  1455.   szOID_RSA_SMIMECapabilities = '1.2.840.113549.1.9.15';
  1456.   {$EXTERNALSYM szOID_RSA_SMIMECapabilities}
  1457.   szOID_RSA_preferSignedData  = '1.2.840.113549.1.9.15.1';
  1458.   {$EXTERNALSYM szOID_RSA_preferSignedData}
  1459.   szOID_RSA_SMIMEalg            = '1.2.840.113549.1.9.16.3';
  1460.   {$EXTERNALSYM szOID_RSA_SMIMEalg}
  1461.   szOID_RSA_SMIMEalgESDH        = '1.2.840.113549.1.9.16.3.5';
  1462.   {$EXTERNALSYM szOID_RSA_SMIMEalgESDH}
  1463.   szOID_RSA_SMIMEalgCMS3DESwrap = '1.2.840.113549.1.9.16.3.6';
  1464.   {$EXTERNALSYM szOID_RSA_SMIMEalgCMS3DESwrap}
  1465.   szOID_RSA_SMIMEalgCMSRC2wrap  = '1.2.840.113549.1.9.16.3.7';
  1466.   {$EXTERNALSYM szOID_RSA_SMIMEalgCMSRC2wrap}
  1467.   szOID_RSA_MD2 = '1.2.840.113549.2.2';
  1468.   {$EXTERNALSYM szOID_RSA_MD2}
  1469.   szOID_RSA_MD4 = '1.2.840.113549.2.4';
  1470.   {$EXTERNALSYM szOID_RSA_MD4}
  1471.   szOID_RSA_MD5 = '1.2.840.113549.2.5';
  1472.   {$EXTERNALSYM szOID_RSA_MD5}
  1473.   szOID_RSA_RC2CBC       = '1.2.840.113549.3.2';
  1474.   {$EXTERNALSYM szOID_RSA_RC2CBC}
  1475.   szOID_RSA_RC4          = '1.2.840.113549.3.4';
  1476.   {$EXTERNALSYM szOID_RSA_RC4}
  1477.   szOID_RSA_DES_EDE3_CBC = '1.2.840.113549.3.7';
  1478.   {$EXTERNALSYM szOID_RSA_DES_EDE3_CBC}
  1479.   szOID_RSA_RC5_CBCPad   = '1.2.840.113549.3.9';
  1480.   {$EXTERNALSYM szOID_RSA_RC5_CBCPad}
  1481.   szOID_ANSI_X942    = '1.2.840.10046';
  1482.   {$EXTERNALSYM szOID_ANSI_X942}
  1483.   szOID_ANSI_X942_DH = '1.2.840.10046.2.1';
  1484.   {$EXTERNALSYM szOID_ANSI_X942_DH}
  1485.   szOID_X957         = '1.2.840.10040';
  1486.   {$EXTERNALSYM szOID_X957}
  1487.   szOID_X957_DSA     = '1.2.840.10040.4.1';
  1488.   {$EXTERNALSYM szOID_X957_DSA}
  1489.   szOID_X957_SHA1DSA = '1.2.840.10040.4.3';
  1490.   {$EXTERNALSYM szOID_X957_SHA1DSA}
  1491. // ITU-T UsefulDefinitions
  1492.   szOID_DS         = '2.5';
  1493.   {$EXTERNALSYM szOID_DS}
  1494.   szOID_DSALG      = '2.5.8';
  1495.   {$EXTERNALSYM szOID_DSALG}
  1496.   szOID_DSALG_CRPT = '2.5.8.1';
  1497.   {$EXTERNALSYM szOID_DSALG_CRPT}
  1498.   szOID_DSALG_HASH = '2.5.8.2';
  1499.   {$EXTERNALSYM szOID_DSALG_HASH}
  1500.   szOID_DSALG_SIGN = '2.5.8.3';
  1501.   {$EXTERNALSYM szOID_DSALG_SIGN}
  1502.   szOID_DSALG_RSA  = '2.5.8.1.1';
  1503.   {$EXTERNALSYM szOID_DSALG_RSA}
  1504. // NIST OSE Implementors' Workshop (OIW)
  1505. // http://nemo.ncsl.nist.gov/oiw/agreements/stable/OSI/12s_9506.w51
  1506. // http://nemo.ncsl.nist.gov/oiw/agreements/working/OSI/12w_9503.w51
  1507.   szOID_OIW = '1.3.14';
  1508.   {$EXTERNALSYM szOID_OIW}
  1509. // NIST OSE Implementors' Workshop (OIW) Security SIG algorithm identifiers
  1510.   szOID_OIWSEC             = '1.3.14.3.2';
  1511.   {$EXTERNALSYM szOID_OIWSEC}
  1512.   szOID_OIWSEC_md4RSA      = '1.3.14.3.2.2';
  1513.   {$EXTERNALSYM szOID_OIWSEC_md4RSA}
  1514.   szOID_OIWSEC_md5RSA      = '1.3.14.3.2.3';
  1515.   {$EXTERNALSYM szOID_OIWSEC_md5RSA}
  1516.   szOID_OIWSEC_md4RSA2     = '1.3.14.3.2.4';
  1517.   {$EXTERNALSYM szOID_OIWSEC_md4RSA2}
  1518.   szOID_OIWSEC_desECB      = '1.3.14.3.2.6';
  1519.   {$EXTERNALSYM szOID_OIWSEC_desECB}
  1520.   szOID_OIWSEC_desCBC      = '1.3.14.3.2.7';
  1521.   {$EXTERNALSYM szOID_OIWSEC_desCBC}
  1522.   szOID_OIWSEC_desOFB      = '1.3.14.3.2.8';
  1523.   {$EXTERNALSYM szOID_OIWSEC_desOFB}
  1524.   szOID_OIWSEC_desCFB      = '1.3.14.3.2.9';
  1525.   {$EXTERNALSYM szOID_OIWSEC_desCFB}
  1526.   szOID_OIWSEC_desMAC      = '1.3.14.3.2.10';
  1527.   {$EXTERNALSYM szOID_OIWSEC_desMAC}
  1528.   szOID_OIWSEC_rsaSign     = '1.3.14.3.2.11';
  1529.   {$EXTERNALSYM szOID_OIWSEC_rsaSign}
  1530.   szOID_OIWSEC_dsa         = '1.3.14.3.2.12';
  1531.   {$EXTERNALSYM szOID_OIWSEC_dsa}
  1532.   szOID_OIWSEC_shaDSA      = '1.3.14.3.2.13';
  1533.   {$EXTERNALSYM szOID_OIWSEC_shaDSA}
  1534.   szOID_OIWSEC_mdc2RSA     = '1.3.14.3.2.14';
  1535.   {$EXTERNALSYM szOID_OIWSEC_mdc2RSA}
  1536.   szOID_OIWSEC_shaRSA      = '1.3.14.3.2.15';
  1537.   {$EXTERNALSYM szOID_OIWSEC_shaRSA}
  1538.   szOID_OIWSEC_dhCommMod   = '1.3.14.3.2.16';
  1539.   {$EXTERNALSYM szOID_OIWSEC_dhCommMod}
  1540.   szOID_OIWSEC_desEDE      = '1.3.14.3.2.17';
  1541.   {$EXTERNALSYM szOID_OIWSEC_desEDE}
  1542.   szOID_OIWSEC_sha         = '1.3.14.3.2.18';
  1543.   {$EXTERNALSYM szOID_OIWSEC_sha}
  1544.   szOID_OIWSEC_mdc2        = '1.3.14.3.2.19';
  1545.   {$EXTERNALSYM szOID_OIWSEC_mdc2}
  1546.   szOID_OIWSEC_dsaComm     = '1.3.14.3.2.20';
  1547.   {$EXTERNALSYM szOID_OIWSEC_dsaComm}
  1548.   szOID_OIWSEC_dsaCommSHA  = '1.3.14.3.2.21';
  1549.   {$EXTERNALSYM szOID_OIWSEC_dsaCommSHA}
  1550.   szOID_OIWSEC_rsaXchg     = '1.3.14.3.2.22';
  1551.   {$EXTERNALSYM szOID_OIWSEC_rsaXchg}
  1552.   szOID_OIWSEC_keyHashSeal = '1.3.14.3.2.23';
  1553.   {$EXTERNALSYM szOID_OIWSEC_keyHashSeal}
  1554.   szOID_OIWSEC_md2RSASign  = '1.3.14.3.2.24';
  1555.   {$EXTERNALSYM szOID_OIWSEC_md2RSASign}
  1556.   szOID_OIWSEC_md5RSASign  = '1.3.14.3.2.25';
  1557.   {$EXTERNALSYM szOID_OIWSEC_md5RSASign}
  1558.   szOID_OIWSEC_sha1        = '1.3.14.3.2.26';
  1559.   {$EXTERNALSYM szOID_OIWSEC_sha1}
  1560.   szOID_OIWSEC_dsaSHA1     = '1.3.14.3.2.27';
  1561.   {$EXTERNALSYM szOID_OIWSEC_dsaSHA1}
  1562.   szOID_OIWSEC_dsaCommSHA1 = '1.3.14.3.2.28';
  1563.   {$EXTERNALSYM szOID_OIWSEC_dsaCommSHA1}
  1564.   szOID_OIWSEC_sha1RSASign = '1.3.14.3.2.29';
  1565.   {$EXTERNALSYM szOID_OIWSEC_sha1RSASign}
  1566. // NIST OSE Implementors' Workshop (OIW) Directory SIG algorithm identifiers
  1567.   szOID_OIWDIR        = '1.3.14.7.2';
  1568.   {$EXTERNALSYM szOID_OIWDIR}
  1569.   szOID_OIWDIR_CRPT   = '1.3.14.7.2.1';
  1570.   {$EXTERNALSYM szOID_OIWDIR_CRPT}
  1571.   szOID_OIWDIR_HASH   = '1.3.14.7.2.2';
  1572.   {$EXTERNALSYM szOID_OIWDIR_HASH}
  1573.   szOID_OIWDIR_SIGN   = '1.3.14.7.2.3';
  1574.   {$EXTERNALSYM szOID_OIWDIR_SIGN}
  1575.   szOID_OIWDIR_md2    = '1.3.14.7.2.2.1';
  1576.   {$EXTERNALSYM szOID_OIWDIR_md2}
  1577.   szOID_OIWDIR_md2RSA = '1.3.14.7.2.3.1';
  1578.   {$EXTERNALSYM szOID_OIWDIR_md2RSA}
  1579. // INFOSEC Algorithms
  1580. // joint-iso-ccitt(2) country(16) us(840) organization(1) us-government(101) dod(2) id-infosec(1)
  1581.   szOID_INFOSEC                       = '2.16.840.1.101.2.1';
  1582.   {$EXTERNALSYM szOID_INFOSEC}
  1583.   szOID_INFOSEC_sdnsSignature         = '2.16.840.1.101.2.1.1.1';
  1584.   {$EXTERNALSYM szOID_INFOSEC_sdnsSignature}
  1585.   szOID_INFOSEC_mosaicSignature       = '2.16.840.1.101.2.1.1.2';
  1586.   {$EXTERNALSYM szOID_INFOSEC_mosaicSignature}
  1587.   szOID_INFOSEC_sdnsConfidentiality   = '2.16.840.1.101.2.1.1.3';
  1588.   {$EXTERNALSYM szOID_INFOSEC_sdnsConfidentiality}
  1589.   szOID_INFOSEC_mosaicConfidentiality = '2.16.840.1.101.2.1.1.4';
  1590.   {$EXTERNALSYM szOID_INFOSEC_mosaicConfidentiality}
  1591.   szOID_INFOSEC_sdnsIntegrity         = '2.16.840.1.101.2.1.1.5';
  1592.   {$EXTERNALSYM szOID_INFOSEC_sdnsIntegrity}
  1593.   szOID_INFOSEC_mosaicIntegrity       = '2.16.840.1.101.2.1.1.6';
  1594.   {$EXTERNALSYM szOID_INFOSEC_mosaicIntegrity}
  1595.   szOID_INFOSEC_sdnsTokenProtection   = '2.16.840.1.101.2.1.1.7';
  1596.   {$EXTERNALSYM szOID_INFOSEC_sdnsTokenProtection}
  1597.   szOID_INFOSEC_mosaicTokenProtection = '2.16.840.1.101.2.1.1.8';
  1598.   {$EXTERNALSYM szOID_INFOSEC_mosaicTokenProtection}
  1599.   szOID_INFOSEC_sdnsKeyManagement     = '2.16.840.1.101.2.1.1.9';
  1600.   {$EXTERNALSYM szOID_INFOSEC_sdnsKeyManagement}
  1601.   szOID_INFOSEC_mosaicKeyManagement   = '2.16.840.1.101.2.1.1.10';
  1602.   {$EXTERNALSYM szOID_INFOSEC_mosaicKeyManagement}
  1603.   szOID_INFOSEC_sdnsKMandSig          = '2.16.840.1.101.2.1.1.11';
  1604.   {$EXTERNALSYM szOID_INFOSEC_sdnsKMandSig}
  1605.   szOID_INFOSEC_mosaicKMandSig        = '2.16.840.1.101.2.1.1.12';
  1606.   {$EXTERNALSYM szOID_INFOSEC_mosaicKMandSig}
  1607.   szOID_INFOSEC_SuiteASignature       = '2.16.840.1.101.2.1.1.13';
  1608.   {$EXTERNALSYM szOID_INFOSEC_SuiteASignature}
  1609.   szOID_INFOSEC_SuiteAConfidentiality = '2.16.840.1.101.2.1.1.14';
  1610.   {$EXTERNALSYM szOID_INFOSEC_SuiteAConfidentiality}
  1611.   szOID_INFOSEC_SuiteAIntegrity       = '2.16.840.1.101.2.1.1.15';
  1612.   {$EXTERNALSYM szOID_INFOSEC_SuiteAIntegrity}
  1613.   szOID_INFOSEC_SuiteATokenProtection = '2.16.840.1.101.2.1.1.16';
  1614.   {$EXTERNALSYM szOID_INFOSEC_SuiteATokenProtection}
  1615.   szOID_INFOSEC_SuiteAKeyManagement   = '2.16.840.1.101.2.1.1.17';
  1616.   {$EXTERNALSYM szOID_INFOSEC_SuiteAKeyManagement}
  1617.   szOID_INFOSEC_SuiteAKMandSig        = '2.16.840.1.101.2.1.1.18';
  1618.   {$EXTERNALSYM szOID_INFOSEC_SuiteAKMandSig}
  1619.   szOID_INFOSEC_mosaicUpdatedSig      = '2.16.840.1.101.2.1.1.19';
  1620.   {$EXTERNALSYM szOID_INFOSEC_mosaicUpdatedSig}
  1621.   szOID_INFOSEC_mosaicKMandUpdSig     = '2.16.840.1.101.2.1.1.20';
  1622.   {$EXTERNALSYM szOID_INFOSEC_mosaicKMandUpdSig}
  1623.   szOID_INFOSEC_mosaicUpdatedInteg    = '2.16.840.1.101.2.1.1.21';
  1624.   {$EXTERNALSYM szOID_INFOSEC_mosaicUpdatedInteg}
  1625. type
  1626.   PCRYPT_OBJID_TABLE = ^CRYPT_OBJID_TABLE;
  1627.   {$EXTERNALSYM PCRYPT_OBJID_TABLE}
  1628.   _CRYPT_OBJID_TABLE = record
  1629.     dwAlgId: DWORD;
  1630.     pszObjId: LPCSTR;
  1631.   end;
  1632.   {$EXTERNALSYM _CRYPT_OBJID_TABLE}
  1633.   CRYPT_OBJID_TABLE = _CRYPT_OBJID_TABLE;
  1634.   {$EXTERNALSYM CRYPT_OBJID_TABLE}
  1635.   TCryptObjIdTable = CRYPT_OBJID_TABLE;
  1636.   PCryptObjIdTable = PCRYPT_OBJID_TABLE;
  1637. //+-------------------------------------------------------------------------
  1638. //  PKCS #1 HashInfo (DigestInfo)
  1639. //--------------------------------------------------------------------------
  1640.   PCRYPT_HASH_INFO = ^CRYPT_HASH_INFO;
  1641.   {$EXTERNALSYM PCRYPT_HASH_INFO}
  1642.   _CRYPT_HASH_INFO = record
  1643.     HashAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  1644.     Hash: CRYPT_HASH_BLOB;
  1645.   end;
  1646.   {$EXTERNALSYM _CRYPT_HASH_INFO}
  1647.   CRYPT_HASH_INFO = _CRYPT_HASH_INFO;
  1648.   {$EXTERNALSYM CRYPT_HASH_INFO}
  1649.   TCryptHashInfo = CRYPT_HASH_INFO;
  1650.   PCryptHashInfo = PCRYPT_HASH_INFO;
  1651. //+-------------------------------------------------------------------------
  1652. //  Type used for an extension to an encoded content
  1653. //
  1654. //  Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  1655. //--------------------------------------------------------------------------
  1656.   PCERT_EXTENSION = ^CERT_EXTENSION;
  1657.   {$EXTERNALSYM PCERT_EXTENSION}
  1658.   _CERT_EXTENSION = record
  1659.     pszObjId: LPSTR;
  1660.     fCritical: BOOL;
  1661.     Value: CRYPT_OBJID_BLOB;
  1662.   end;
  1663.   {$EXTERNALSYM _CERT_EXTENSION}
  1664.   CERT_EXTENSION = _CERT_EXTENSION;
  1665.   {$EXTERNALSYM CERT_EXTENSION}
  1666.   TCertExtension = CERT_EXTENSION;
  1667.   PCertExtension = PCERT_EXTENSION;
  1668. //+-------------------------------------------------------------------------
  1669. //  AttributeTypeValue
  1670. //
  1671. //  Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  1672. //--------------------------------------------------------------------------
  1673.   PCRYPT_ATTRIBUTE_TYPE_VALUE = ^CRYPT_ATTRIBUTE_TYPE_VALUE;
  1674.   {$EXTERNALSYM PCRYPT_ATTRIBUTE_TYPE_VALUE}
  1675.   _CRYPT_ATTRIBUTE_TYPE_VALUE = record
  1676.     pszObjId: LPSTR;
  1677.     Value: CRYPT_OBJID_BLOB;
  1678.   end;
  1679.   {$EXTERNALSYM _CRYPT_ATTRIBUTE_TYPE_VALUE}
  1680.   CRYPT_ATTRIBUTE_TYPE_VALUE = _CRYPT_ATTRIBUTE_TYPE_VALUE;
  1681.   {$EXTERNALSYM CRYPT_ATTRIBUTE_TYPE_VALUE}
  1682.   TCryptAttributeTypeValue = CRYPT_ATTRIBUTE_TYPE_VALUE;
  1683.   PCryptAttributeTypeValue = PCRYPT_ATTRIBUTE_TYPE_VALUE;
  1684. //+-------------------------------------------------------------------------
  1685. //  Attributes
  1686. //
  1687. //  Where the Value's PATTR_BLOBs are in their encoded representation.
  1688. //--------------------------------------------------------------------------
  1689.   PCRYPT_ATTRIBUTE = ^CRYPT_ATTRIBUTE;
  1690.   {$EXTERNALSYM PCRYPT_ATTRIBUTE}
  1691.   _CRYPT_ATTRIBUTE = record
  1692.     pszObjId: LPSTR;
  1693.     cValue: DWORD;
  1694.     rgValue: PCRYPT_ATTR_BLOB;
  1695.   end;
  1696.   {$EXTERNALSYM _CRYPT_ATTRIBUTE}
  1697.   CRYPT_ATTRIBUTE = _CRYPT_ATTRIBUTE;
  1698.   {$EXTERNALSYM CRYPT_ATTRIBUTE}
  1699.   TCryptAttribute = CRYPT_ATTRIBUTE;
  1700.   PCryptAttribute = PCRYPT_ATTRIBUTE;
  1701.   PCRYPT_ATTRIBUTES = ^CRYPT_ATTRIBUTES;
  1702.   {$EXTERNALSYM PCRYPT_ATTRIBUTES}
  1703.   _CRYPT_ATTRIBUTES = record
  1704.     cAttr: DWORD;
  1705.     rgAttr: PCRYPT_ATTRIBUTE;
  1706.   end;
  1707.   {$EXTERNALSYM _CRYPT_ATTRIBUTES}
  1708.   CRYPT_ATTRIBUTES = _CRYPT_ATTRIBUTES;
  1709.   {$EXTERNALSYM CRYPT_ATTRIBUTES}
  1710.   TCryptAttributes = CRYPT_ATTRIBUTES;
  1711.   PCryptAttributes = PCRYPT_ATTRIBUTES;
  1712. //+-------------------------------------------------------------------------
  1713. //  Attributes making up a Relative Distinguished Name (CERT_RDN)
  1714. //
  1715. //  The interpretation of the Value depends on the dwValueType.
  1716. //  See below for a list of the types.
  1717. //--------------------------------------------------------------------------
  1718.   PCERT_RDN_ATTR = ^CERT_RDN_ATTR;
  1719.   {$EXTERNALSYM PCERT_RDN_ATTR}
  1720.   _CERT_RDN_ATTR = record
  1721.     pszObjId: LPSTR;
  1722.     dwValueType: DWORD;
  1723.     Value: CERT_RDN_VALUE_BLOB;
  1724.   end;
  1725.   {$EXTERNALSYM _CERT_RDN_ATTR}
  1726.   CERT_RDN_ATTR = _CERT_RDN_ATTR;
  1727.   {$EXTERNALSYM CERT_RDN_ATTR}
  1728.   TCertRdnAttr = CERT_RDN_ATTR;
  1729.   PCertRdnAttr = PCERT_RDN_ATTR;
  1730. //+-------------------------------------------------------------------------
  1731. //  CERT_RDN attribute Object Identifiers
  1732. //--------------------------------------------------------------------------
  1733. // Labeling attribute types:
  1734. const
  1735.   szOID_COMMON_NAME          = '2.5.4.3'; // case-ignore string
  1736.   {$EXTERNALSYM szOID_COMMON_NAME}
  1737.   szOID_SUR_NAME             = '2.5.4.4'; // case-ignore string
  1738.   {$EXTERNALSYM szOID_SUR_NAME}
  1739.   szOID_DEVICE_SERIAL_NUMBER = '2.5.4.5'; // printable string
  1740.   {$EXTERNALSYM szOID_DEVICE_SERIAL_NUMBER}
  1741. // Geographic attribute types:
  1742.   szOID_COUNTRY_NAME           = '2.5.4.6'; // printable 2char string
  1743.   {$EXTERNALSYM szOID_COUNTRY_NAME}
  1744.   szOID_LOCALITY_NAME          = '2.5.4.7'; // case-ignore string
  1745.   {$EXTERNALSYM szOID_LOCALITY_NAME}
  1746.   szOID_STATE_OR_PROVINCE_NAME = '2.5.4.8'; // case-ignore string
  1747.   {$EXTERNALSYM szOID_STATE_OR_PROVINCE_NAME}
  1748.   szOID_STREET_ADDRESS         = '2.5.4.9'; // case-ignore string
  1749.   {$EXTERNALSYM szOID_STREET_ADDRESS}
  1750. // Organizational attribute types:
  1751.   szOID_ORGANIZATION_NAME        = '2.5.4.10'; // case-ignore string
  1752.   {$EXTERNALSYM szOID_ORGANIZATION_NAME}
  1753.   szOID_ORGANIZATIONAL_UNIT_NAME = '2.5.4.11'; // case-ignore string
  1754.   {$EXTERNALSYM szOID_ORGANIZATIONAL_UNIT_NAME}
  1755.   szOID_TITLE                    = '2.5.4.12'; // case-ignore string
  1756.   {$EXTERNALSYM szOID_TITLE}
  1757. // Explanatory attribute types:
  1758.   szOID_DESCRIPTION       = '2.5.4.13'; // case-ignore string
  1759.   {$EXTERNALSYM szOID_DESCRIPTION}
  1760.   szOID_SEARCH_GUIDE      = '2.5.4.14';
  1761.   {$EXTERNALSYM szOID_SEARCH_GUIDE}
  1762.   szOID_BUSINESS_CATEGORY = '2.5.4.15'; // case-ignore string
  1763.   {$EXTERNALSYM szOID_BUSINESS_CATEGORY}
  1764. // Postal addressing attribute types:
  1765.   szOID_POSTAL_ADDRESS                = '2.5.4.16';
  1766.   {$EXTERNALSYM szOID_POSTAL_ADDRESS}
  1767.   szOID_POSTAL_CODE                   = '2.5.4.17'; // case-ignore string
  1768.   {$EXTERNALSYM szOID_POSTAL_CODE}
  1769.   szOID_POST_OFFICE_BOX               = '2.5.4.18'; // case-ignore string
  1770.   {$EXTERNALSYM szOID_POST_OFFICE_BOX}
  1771.   szOID_PHYSICAL_DELIVERY_OFFICE_NAME = '2.5.4.19'; // case-ignore string
  1772.   {$EXTERNALSYM szOID_PHYSICAL_DELIVERY_OFFICE_NAME}
  1773. // Telecommunications addressing attribute types:
  1774.   szOID_TELEPHONE_NUMBER             = '2.5.4.20'; // telephone number
  1775.   {$EXTERNALSYM szOID_TELEPHONE_NUMBER}
  1776.   szOID_TELEX_NUMBER                 = '2.5.4.21';
  1777.   {$EXTERNALSYM szOID_TELEX_NUMBER}
  1778.   szOID_TELETEXT_TERMINAL_IDENTIFIER = '2.5.4.22';
  1779.   {$EXTERNALSYM szOID_TELETEXT_TERMINAL_IDENTIFIER}
  1780.   szOID_FACSIMILE_TELEPHONE_NUMBER   = '2.5.4.23';
  1781.   {$EXTERNALSYM szOID_FACSIMILE_TELEPHONE_NUMBER}
  1782.   szOID_X21_ADDRESS                  = '2.5.4.24'; // numeric string
  1783.   {$EXTERNALSYM szOID_X21_ADDRESS}
  1784.   szOID_INTERNATIONAL_ISDN_NUMBER    = '2.5.4.25'; // numeric string
  1785.   {$EXTERNALSYM szOID_INTERNATIONAL_ISDN_NUMBER}
  1786.   szOID_REGISTERED_ADDRESS           = '2.5.4.26';
  1787.   {$EXTERNALSYM szOID_REGISTERED_ADDRESS}
  1788.   szOID_DESTINATION_INDICATOR        = '2.5.4.27'; // printable string
  1789.   {$EXTERNALSYM szOID_DESTINATION_INDICATOR}
  1790. // Preference attribute types:
  1791.   szOID_PREFERRED_DELIVERY_METHOD = '2.5.4.28';
  1792.   {$EXTERNALSYM szOID_PREFERRED_DELIVERY_METHOD}
  1793. // OSI application attribute types:
  1794.   szOID_PRESENTATION_ADDRESS          = '2.5.4.29';
  1795.   {$EXTERNALSYM szOID_PRESENTATION_ADDRESS}
  1796.   szOID_SUPPORTED_APPLICATION_CONTEXT = '2.5.4.30';
  1797.   {$EXTERNALSYM szOID_SUPPORTED_APPLICATION_CONTEXT}
  1798. // Relational application attribute types:
  1799.   szOID_MEMBER        = '2.5.4.31';
  1800.   {$EXTERNALSYM szOID_MEMBER}
  1801.   szOID_OWNER         = '2.5.4.32';
  1802.   {$EXTERNALSYM szOID_OWNER}
  1803.   szOID_ROLE_OCCUPANT = '2.5.4.33';
  1804.   {$EXTERNALSYM szOID_ROLE_OCCUPANT}
  1805.   szOID_SEE_ALSO      = '2.5.4.34';
  1806.   {$EXTERNALSYM szOID_SEE_ALSO}
  1807. // Security attribute types:
  1808.   szOID_USER_PASSWORD               = '2.5.4.35';
  1809.   {$EXTERNALSYM szOID_USER_PASSWORD}
  1810.   szOID_USER_CERTIFICATE            = '2.5.4.36';
  1811.   {$EXTERNALSYM szOID_USER_CERTIFICATE}
  1812.   szOID_CA_CERTIFICATE              = '2.5.4.37';
  1813.   {$EXTERNALSYM szOID_CA_CERTIFICATE}
  1814.   szOID_AUTHORITY_REVOCATION_LIST   = '2.5.4.38';
  1815.   {$EXTERNALSYM szOID_AUTHORITY_REVOCATION_LIST}
  1816.   szOID_CERTIFICATE_REVOCATION_LIST = '2.5.4.39';
  1817.   {$EXTERNALSYM szOID_CERTIFICATE_REVOCATION_LIST}
  1818.   szOID_CROSS_CERTIFICATE_PAIR      = '2.5.4.40';
  1819.   {$EXTERNALSYM szOID_CROSS_CERTIFICATE_PAIR}
  1820. // Undocumented attribute types???
  1821. //#define szOID_???                         "2.5.4.41"
  1822.   szOID_GIVEN_NAME = '2.5.4.42'; // case-ignore string
  1823.   {$EXTERNALSYM szOID_GIVEN_NAME}
  1824.   szOID_INITIALS   = '2.5.4.43'; // case-ignore string
  1825.   {$EXTERNALSYM szOID_INITIALS}
  1826. // The DN Qualifier attribute type specifies disambiguating information to add
  1827. // to the relative distinguished name of an entry. It is intended to be used
  1828. // for entries held in multiple DSAs which would otherwise have the same name,
  1829. // and that its value be the same in a given DSA for all entries to which
  1830. // the information has been added.
  1831.   szOID_DN_QUALIFIER = '2.5.4.46';
  1832.   {$EXTERNALSYM szOID_DN_QUALIFIER}
  1833. // Pilot user attribute types:
  1834.   szOID_DOMAIN_COMPONENT = '0.9.2342.19200300.100.1.25'; // IA5, UTF8 string
  1835.   {$EXTERNALSYM szOID_DOMAIN_COMPONENT}
  1836. // used for PKCS 12 attributes
  1837.   szOID_PKCS_12_FRIENDLY_NAME_ATTR     = '1.2.840.113549.1.9.20';
  1838.   {$EXTERNALSYM szOID_PKCS_12_FRIENDLY_NAME_ATTR}
  1839.   szOID_PKCS_12_LOCAL_KEY_ID           = '1.2.840.113549.1.9.21';
  1840.   {$EXTERNALSYM szOID_PKCS_12_LOCAL_KEY_ID}
  1841.   szOID_PKCS_12_KEY_PROVIDER_NAME_ATTR = '1.3.6.1.4.1.311.17.1';
  1842.   {$EXTERNALSYM szOID_PKCS_12_KEY_PROVIDER_NAME_ATTR}
  1843.   szOID_LOCAL_MACHINE_KEYSET           = '1.3.6.1.4.1.311.17.2';
  1844.   {$EXTERNALSYM szOID_LOCAL_MACHINE_KEYSET}
  1845. //+-------------------------------------------------------------------------
  1846. //  Microsoft CERT_RDN attribute Object Identifiers
  1847. //--------------------------------------------------------------------------
  1848. // Special RDN containing the KEY_ID. Its value type is CERT_RDN_OCTET_STRING.
  1849.   szOID_KEYID_RDN = '1.3.6.1.4.1.311.10.7.1';
  1850.   {$EXTERNALSYM szOID_KEYID_RDN}
  1851. //+-------------------------------------------------------------------------
  1852. //  CERT_RDN Attribute Value Types
  1853. //
  1854. //  For RDN_ENCODED_BLOB, the Value's CERT_RDN_VALUE_BLOB is in its encoded
  1855. //  representation. Otherwise, its an array of bytes.
  1856. //
  1857. //  For all CERT_RDN types, Value.cbData is always the number of bytes, not
  1858. //  necessarily the number of elements in the string. For instance,
  1859. //  RDN_UNIVERSAL_STRING is an array of ints (cbData == intCnt * 4) and
  1860. //  RDN_BMP_STRING is an array of unsigned shorts (cbData == ushortCnt * 2).
  1861. //
  1862. //  A RDN_UTF8_STRING is an array of UNICODE characters (cbData == charCnt *2).
  1863. //  These UNICODE characters are encoded as UTF8 8 bit characters.
  1864. //
  1865. //  For CertDecodeName, two 0 bytes are always appended to the end of the
  1866. //  string (ensures a CHAR or WCHAR string is null terminated).
  1867. //  These added 0 bytes are't included in the BLOB.cbData.
  1868. //--------------------------------------------------------------------------
  1869.   CERT_RDN_ANY_TYPE         = 0;
  1870.   {$EXTERNALSYM CERT_RDN_ANY_TYPE}
  1871.   CERT_RDN_ENCODED_BLOB     = 1;
  1872.   {$EXTERNALSYM CERT_RDN_ENCODED_BLOB}
  1873.   CERT_RDN_OCTET_STRING     = 2;
  1874.   {$EXTERNALSYM CERT_RDN_OCTET_STRING}
  1875.   CERT_RDN_NUMERIC_STRING   = 3;
  1876.   {$EXTERNALSYM CERT_RDN_NUMERIC_STRING}
  1877.   CERT_RDN_PRINTABLE_STRING = 4;
  1878.   {$EXTERNALSYM CERT_RDN_PRINTABLE_STRING}
  1879.   CERT_RDN_TELETEX_STRING   = 5;
  1880.   {$EXTERNALSYM CERT_RDN_TELETEX_STRING}
  1881.   CERT_RDN_T61_STRING       = 5;
  1882.   {$EXTERNALSYM CERT_RDN_T61_STRING}
  1883.   CERT_RDN_VIDEOTEX_STRING  = 6;
  1884.   {$EXTERNALSYM CERT_RDN_VIDEOTEX_STRING}
  1885.   CERT_RDN_IA5_STRING       = 7;
  1886.   {$EXTERNALSYM CERT_RDN_IA5_STRING}
  1887.   CERT_RDN_GRAPHIC_STRING   = 8;
  1888.   {$EXTERNALSYM CERT_RDN_GRAPHIC_STRING}
  1889.   CERT_RDN_VISIBLE_STRING   = 9;
  1890.   {$EXTERNALSYM CERT_RDN_VISIBLE_STRING}
  1891.   CERT_RDN_ISO646_STRING    = 9;
  1892.   {$EXTERNALSYM CERT_RDN_ISO646_STRING}
  1893.   CERT_RDN_GENERAL_STRING   = 10;
  1894.   {$EXTERNALSYM CERT_RDN_GENERAL_STRING}
  1895.   CERT_RDN_UNIVERSAL_STRING = 11;
  1896.   {$EXTERNALSYM CERT_RDN_UNIVERSAL_STRING}
  1897.   CERT_RDN_INT4_STRING      = 11;
  1898.   {$EXTERNALSYM CERT_RDN_INT4_STRING}
  1899.   CERT_RDN_BMP_STRING       = 12;
  1900.   {$EXTERNALSYM CERT_RDN_BMP_STRING}
  1901.   CERT_RDN_UNICODE_STRING   = 12;
  1902.   {$EXTERNALSYM CERT_RDN_UNICODE_STRING}
  1903.   CERT_RDN_UTF8_STRING      = 13;
  1904.   {$EXTERNALSYM CERT_RDN_UTF8_STRING}
  1905.   CERT_RDN_TYPE_MASK  = $000000FF;
  1906.   {$EXTERNALSYM CERT_RDN_TYPE_MASK}
  1907.   CERT_RDN_FLAGS_MASK = DWORD($FF000000);
  1908.   {$EXTERNALSYM CERT_RDN_FLAGS_MASK}
  1909. //+-------------------------------------------------------------------------
  1910. //  Flags that can be or'ed with the above Value Type when encoding/decoding
  1911. //--------------------------------------------------------------------------
  1912. // For encoding: when set, CERT_RDN_T61_STRING is selected instead of
  1913. // CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF
  1914.   CERT_RDN_ENABLE_T61_UNICODE_FLAG = DWORD($80000000);
  1915.   {$EXTERNALSYM CERT_RDN_ENABLE_T61_UNICODE_FLAG}
  1916. // For encoding: when set, CERT_RDN_UTF8_STRING is selected instead of
  1917. // CERT_RDN_UNICODE_STRING.
  1918.   CERT_RDN_ENABLE_UTF8_UNICODE_FLAG = $20000000;
  1919.   {$EXTERNALSYM CERT_RDN_ENABLE_UTF8_UNICODE_FLAG}
  1920. // For encoding: when set, the characters aren't checked to see if they
  1921. // are valid for the Value Type.
  1922.   CERT_RDN_DISABLE_CHECK_TYPE_FLAG = $40000000;
  1923.   {$EXTERNALSYM CERT_RDN_DISABLE_CHECK_TYPE_FLAG}
  1924. // For decoding: by default, CERT_RDN_T61_STRING values are initially decoded
  1925. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  1926. // Setting this flag skips the initial attempt to decode as UTF8.
  1927.   CERT_RDN_DISABLE_IE4_UTF8_FLAG = $01000000;
  1928.   {$EXTERNALSYM CERT_RDN_DISABLE_IE4_UTF8_FLAG}
  1929. // Macro to check that the dwValueType is a character string and not an
  1930. // encoded blob or octet string
  1931. function IS_CERT_RDN_CHAR_STRING(X: DWORD): Boolean;
  1932. {$EXTERNALSYM IS_CERT_RDN_CHAR_STRING}
  1933. //+-------------------------------------------------------------------------
  1934. //  A CERT_RDN consists of an array of the above attributes
  1935. //--------------------------------------------------------------------------
  1936. type
  1937.   PCERT_RDN = ^CERT_RDN;
  1938.   {$EXTERNALSYM PCERT_RDN}
  1939.   _CERT_RDN = record
  1940.     cRDNAttr: DWORD;
  1941.     rgRDNAttr: PCERT_RDN_ATTR;
  1942.   end;
  1943.   {$EXTERNALSYM _CERT_RDN}
  1944.   CERT_RDN = _CERT_RDN;
  1945.   {$EXTERNALSYM CERT_RDN}
  1946.   TCertRdn = CERT_RDN;
  1947.   PCertRdn = PCERT_RDN;
  1948. //+-------------------------------------------------------------------------
  1949. //  Information stored in a subject's or issuer's name. The information
  1950. //  is represented as an array of the above RDNs.
  1951. //--------------------------------------------------------------------------
  1952.   PCERT_NAME_INFO = ^CERT_NAME_INFO;
  1953.   {$EXTERNALSYM PCERT_NAME_INFO}
  1954.   _CERT_NAME_INFO = record
  1955.     cRDN: DWORD;
  1956.     rgRDN: PCERT_RDN;
  1957.   end;
  1958.   {$EXTERNALSYM _CERT_NAME_INFO}
  1959.   CERT_NAME_INFO = _CERT_NAME_INFO;
  1960.   {$EXTERNALSYM CERT_NAME_INFO}
  1961.   TCertNameInfo = CERT_NAME_INFO;
  1962.   PCertNameInfo = PCERT_NAME_INFO;
  1963. //+-------------------------------------------------------------------------
  1964. //  Name attribute value without the Object Identifier
  1965. //
  1966. //  The interpretation of the Value depends on the dwValueType.
  1967. //  See above for a list of the types.
  1968. //--------------------------------------------------------------------------
  1969.   PCERT_NAME_VALUE = ^CERT_NAME_VALUE;
  1970.   {$EXTERNALSYM PCERT_NAME_VALUE}
  1971.   _CERT_NAME_VALUE = record
  1972.     dwValueType: DWORD;
  1973.     Value: CERT_RDN_VALUE_BLOB;
  1974.   end;
  1975.   {$EXTERNALSYM _CERT_NAME_VALUE}
  1976.   CERT_NAME_VALUE = _CERT_NAME_VALUE;
  1977.   {$EXTERNALSYM CERT_NAME_VALUE}
  1978.   TCertNameValue = CERT_NAME_VALUE;
  1979.   PCertNameValue = PCERT_NAME_VALUE;
  1980. //+-------------------------------------------------------------------------
  1981. //  Public Key Info
  1982. //
  1983. //  The PublicKey is the encoded representation of the information as it is
  1984. //  stored in the bit string
  1985. //--------------------------------------------------------------------------
  1986.   PCERT_PUBLIC_KEY_INFO = ^CERT_PUBLIC_KEY_INFO;
  1987.   {$EXTERNALSYM PCERT_PUBLIC_KEY_INFO}
  1988.   _CERT_PUBLIC_KEY_INFO = record
  1989.     Algorithm: CRYPT_ALGORITHM_IDENTIFIER;
  1990.     PublicKey: CRYPT_BIT_BLOB;
  1991.   end;
  1992.   {$EXTERNALSYM _CERT_PUBLIC_KEY_INFO}
  1993.   CERT_PUBLIC_KEY_INFO = _CERT_PUBLIC_KEY_INFO;
  1994.   {$EXTERNALSYM CERT_PUBLIC_KEY_INFO}
  1995.   TCertPublicKeyInfo = CERT_PUBLIC_KEY_INFO;
  1996.   PCertPublicKeyInfo = PCERT_PUBLIC_KEY_INFO;
  1997. const
  1998.   CERT_RSA_PUBLIC_KEY_OBJID        = szOID_RSA_RSA;
  1999.   {$EXTERNALSYM CERT_RSA_PUBLIC_KEY_OBJID}
  2000.   CERT_DEFAULT_OID_PUBLIC_KEY_SIGN = szOID_RSA_RSA;
  2001.   {$EXTERNALSYM CERT_DEFAULT_OID_PUBLIC_KEY_SIGN}
  2002.   CERT_DEFAULT_OID_PUBLIC_KEY_XCHG = szOID_RSA_RSA;
  2003.   {$EXTERNALSYM CERT_DEFAULT_OID_PUBLIC_KEY_XCHG}
  2004. //+-------------------------------------------------------------------------
  2005. //  structure that contains all the information in a PKCS#8 PrivateKeyInfo
  2006. //--------------------------------------------------------------------------
  2007. type
  2008.   PCRYPT_PRIVATE_KEY_INFO = ^CRYPT_PRIVATE_KEY_INFO;
  2009.   {$EXTERNALSYM PCRYPT_PRIVATE_KEY_INFO}
  2010.   _CRYPT_PRIVATE_KEY_INFO = record
  2011.     Version: DWORD;
  2012.     Algorithm: CRYPT_ALGORITHM_IDENTIFIER;
  2013.     PrivateKey: CRYPT_DER_BLOB;
  2014.     pAttributes: PCRYPT_ATTRIBUTES;
  2015.   end;
  2016.   {$EXTERNALSYM _CRYPT_PRIVATE_KEY_INFO}
  2017.   CRYPT_PRIVATE_KEY_INFO = _CRYPT_PRIVATE_KEY_INFO;
  2018.   {$EXTERNALSYM CRYPT_PRIVATE_KEY_INFO}
  2019.   TCryptPrivateKeyInfo = CRYPT_PRIVATE_KEY_INFO;
  2020.   PCryptPrivateKeyInfo = PCRYPT_PRIVATE_KEY_INFO;
  2021. //+-------------------------------------------------------------------------
  2022. //  structure that contains all the information in a PKCS#8
  2023. //  EncryptedPrivateKeyInfo
  2024. //--------------------------------------------------------------------------
  2025.   PCRYPT_ENCRYPTED_PRIVATE_KEY_INFO = ^CRYPT_ENCRYPTED_PRIVATE_KEY_INFO;
  2026.   {$EXTERNALSYM PCRYPT_ENCRYPTED_PRIVATE_KEY_INFO}
  2027.   _CRYPT_ENCRYPTED_PRIVATE_KEY_INFO = record
  2028.     EncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  2029.     EncryptedPrivateKey: CRYPT_DATA_BLOB;
  2030.   end;
  2031.   {$EXTERNALSYM _CRYPT_ENCRYPTED_PRIVATE_KEY_INFO}
  2032.   CRYPT_ENCRYPTED_PRIVATE_KEY_INFO = _CRYPT_ENCRYPTED_PRIVATE_KEY_INFO;
  2033.   {$EXTERNALSYM CRYPT_ENCRYPTED_PRIVATE_KEY_INFO}
  2034.   TCryptEncryptedPrivateKeyInfo = CRYPT_ENCRYPTED_PRIVATE_KEY_INFO;
  2035.   PCryptEncryptedPrivateKeyInfo = PCRYPT_ENCRYPTED_PRIVATE_KEY_INFO;
  2036. //+-------------------------------------------------------------------------
  2037. // this callback is given when an EncryptedProvateKeyInfo structure is
  2038. // encountered during ImportPKCS8.  the caller is then expected to decrypt
  2039. // the private key and hand back the decrypted contents.
  2040. //
  2041. // the parameters are:
  2042. // Algorithm - the algorithm used to encrypt the PrivateKeyInfo
  2043. // EncryptedPrivateKey - the encrypted private key blob
  2044. // pClearTextKey - a buffer to receive the clear text
  2045. // cbClearTextKey - the number of bytes of the pClearTextKey buffer
  2046. //                  note the if this is zero then this should be
  2047. //                  filled in with the size required to decrypt the
  2048. //                  key into, and pClearTextKey should be ignored
  2049. // pVoidDecryptFunc - this is the pVoid that was passed into the call
  2050. //                    and is preserved and passed back as context
  2051. //+-------------------------------------------------------------------------
  2052. type
  2053.   PCRYPT_DECRYPT_PRIVATE_KEY_FUNC = function (Algorithm: CRYPT_ALGORITHM_IDENTIFIER;
  2054.     EncryptedPrivateKey: CRYPT_DATA_BLOB; pbClearTextKey: LPBYTE;
  2055.     pcbClearTextKey: LPDWORD; pVoidDecryptFunc: LPVOID): BOOL; stdcall;
  2056.   {$EXTERNALSYM PCRYPT_DECRYPT_PRIVATE_KEY_FUNC}
  2057.   PCryptDecryptPrivateKeyFunc = PCRYPT_DECRYPT_PRIVATE_KEY_FUNC;
  2058. //+-------------------------------------------------------------------------
  2059. // this callback is given when creating a PKCS8 EncryptedPrivateKeyInfo.
  2060. // The caller is then expected to encrypt the private key and hand back
  2061. // the encrypted contents.
  2062. //
  2063. // the parameters are:
  2064. // Algorithm - the algorithm used to encrypt the PrivateKeyInfo
  2065. // pClearTextPrivateKey - the cleartext private key to be encrypted
  2066. // pbEncryptedKey - the output encrypted private key blob
  2067. // cbEncryptedKey - the number of bytes of the pbEncryptedKey buffer
  2068. //                  note the if this is zero then this should be
  2069. //                  filled in with the size required to encrypt the
  2070. //                  key into, and pbEncryptedKey should be ignored
  2071. // pVoidEncryptFunc - this is the pVoid that was passed into the call
  2072. //                    and is preserved and passed back as context
  2073. //+-------------------------------------------------------------------------
  2074. type
  2075.   PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC = function (pAlgorithm: PCRYPT_ALGORITHM_IDENTIFIER;
  2076.     pClearTextPrivateKey: PCRYPT_DATA_BLOB; pbEncryptedKey: LPBYTE;
  2077.     pcbEncryptedKey: LPDWORD; pVoidEncryptFunc: LPVOID): BOOL; stdcall;
  2078.   {$EXTERNALSYM PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC}
  2079.   PCryptEncryptPrivateKeyFunc = PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC;
  2080. //+-------------------------------------------------------------------------
  2081. // this callback is given from the context of a ImportPKCS8 calls.  the caller
  2082. // is then expected to hand back an HCRYPTPROV to receive the key being imported
  2083. //
  2084. // the parameters are:
  2085. // pPrivateKeyInfo - pointer to a CRYPT_PRIVATE_KEY_INFO structure which
  2086. //                   describes the key being imported
  2087. // EncryptedPrivateKey - the encrypted private key blob
  2088. // phCryptProv - a pointer to a HCRRYPTPROV to be filled in
  2089. // pVoidResolveFunc - this is the pVoidResolveFunc passed in by the caller in the
  2090. //                    CRYPT_PRIVATE_KEY_BLOB_AND_PARAMS struct
  2091. //+-------------------------------------------------------------------------
  2092. type
  2093.   PCRYPT_RESOLVE_HCRYPTPROV_FUNC = function (pPrivateKeyInfo: PCRYPT_PRIVATE_KEY_INFO;
  2094.     phCryptProv: PHCRYPTPROV; pVoidResolveFunc: LPVOID): BOOL; stdcall;
  2095.   {$EXTERNALSYM PCRYPT_RESOLVE_HCRYPTPROV_FUNC}
  2096.   PCryptResolveHCryptProvFunc = PCRYPT_RESOLVE_HCRYPTPROV_FUNC;
  2097. //+-------------------------------------------------------------------------
  2098. // this struct contains a PKCS8 private key and two pointers to callback
  2099. // functions, with a corresponding pVoids.  the first callback is used to give
  2100. // the caller the opportunity to specify where the key is imported to.  the callback
  2101. // passes the caller the algoroithm OID and key size to use in making the decision.
  2102. // the other callback is used to decrypt the private key if the PKCS8 contains an
  2103. // EncryptedPrivateKeyInfo.  both pVoids are preserved and passed back to the caller
  2104. // in the respective callback
  2105. //+-------------------------------------------------------------------------
  2106.   PCRYPT_PKCS8_IMPORT_PARAMS = ^CRYPT_PKCS8_IMPORT_PARAMS;
  2107.   {$EXTERNALSYM PCRYPT_PKCS8_IMPORT_PARAMS}
  2108.   _CRYPT_PKCS8_IMPORT_PARAMS = record
  2109.     PrivateKey: CRYPT_DIGEST_BLOB; // PKCS8 blob
  2110.     pResolvehCryptProvFunc: PCRYPT_RESOLVE_HCRYPTPROV_FUNC; // optional
  2111.     pVoidResolveFunc: LPVOID; // optional
  2112.     pDecryptPrivateKeyFunc: PCRYPT_DECRYPT_PRIVATE_KEY_FUNC;
  2113.     pVoidDecryptFunc: LPVOID;
  2114.   end;
  2115.   {$EXTERNALSYM _CRYPT_PKCS8_IMPORT_PARAMS}
  2116.   CRYPT_PKCS8_IMPORT_PARAMS = _CRYPT_PKCS8_IMPORT_PARAMS;
  2117.   {$EXTERNALSYM CRYPT_PKCS8_IMPORT_PARAMS}
  2118.   TCryptPkcs8ImportParams = CRYPT_PKCS8_IMPORT_PARAMS;
  2119.   PCryptPkcs8ImportParams = PCRYPT_PKCS8_IMPORT_PARAMS;
  2120.   CRYPT_PRIVATE_KEY_BLOB_AND_PARAMS = CRYPT_PKCS8_IMPORT_PARAMS;
  2121.   {$EXTERNALSYM CRYPT_PRIVATE_KEY_BLOB_AND_PARAMS}
  2122.   PCRYPT_PRIVATE_KEY_BLOB_AND_PARAMS = PCRYPT_PKCS8_IMPORT_PARAMS;
  2123.   {$EXTERNALSYM PCRYPT_PRIVATE_KEY_BLOB_AND_PARAMS}
  2124. //+-------------------------------------------------------------------------
  2125. // this struct contains information identifying a private key and a pointer
  2126. // to a callback function, with a corresponding pVoid. The callback is used
  2127. // to encrypt the private key. If the pEncryptPrivateKeyFunc is NULL, the
  2128. // key will not be encrypted and an EncryptedPrivateKeyInfo will not be generated.
  2129. // The pVoid is preserved and passed back to the caller in the respective callback
  2130. //+-------------------------------------------------------------------------
  2131.   PCRYPT_PKCS8_EXPORT_PARAMS = ^CRYPT_PKCS8_EXPORT_PARAMS;
  2132.   {$EXTERNALSYM PCRYPT_PKCS8_EXPORT_PARAMS}
  2133.   _CRYPT_PKCS8_EXPORT_PARAMS = record
  2134.     hCryptProv: HCRYPTPROV;
  2135.     dwKeySpec: DWORD;
  2136.     pszPrivateKeyObjId: LPSTR;
  2137.     pEncryptPrivateKeyFunc: PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC;
  2138.     pVoidEncryptFunc: LPVOID;
  2139.   end;
  2140.   {$EXTERNALSYM _CRYPT_PKCS8_EXPORT_PARAMS}
  2141.   CRYPT_PKCS8_EXPORT_PARAMS = _CRYPT_PKCS8_EXPORT_PARAMS;
  2142.   {$EXTERNALSYM CRYPT_PKCS8_EXPORT_PARAMS}
  2143.   TCryptPkcs8ExportParams = CRYPT_PKCS8_EXPORT_PARAMS;
  2144.   PCryptPkcs8ExportParams = PCRYPT_PKCS8_EXPORT_PARAMS;
  2145. //+-------------------------------------------------------------------------
  2146. //  Information stored in a certificate
  2147. //
  2148. //  The Issuer, Subject, Algorithm, PublicKey and Extension BLOBs are the
  2149. //  encoded representation of the information.
  2150. //--------------------------------------------------------------------------
  2151.   PCERT_INFO = ^CERT_INFO;
  2152.   {$EXTERNALSYM PCERT_INFO}
  2153.   _CERT_INFO = record
  2154.     dwVersion: DWORD;
  2155.     SerialNumber: CRYPT_INTEGER_BLOB;
  2156.     SignatureAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  2157.     Issuer: CERT_NAME_BLOB;
  2158.     NotBefore: FILETIME;
  2159.     NotAfter: FILETIME;
  2160.     Subject: CERT_NAME_BLOB;
  2161.     SubjectPublicKeyInfo: CERT_PUBLIC_KEY_INFO;
  2162.     IssuerUniqueId: CRYPT_BIT_BLOB;
  2163.     SubjectUniqueId: CRYPT_BIT_BLOB;
  2164.     cExtension: DWORD;
  2165.     rgExtension: PCERT_EXTENSION;
  2166.   end;
  2167.   {$EXTERNALSYM _CERT_INFO}
  2168.   CERT_INFO = _CERT_INFO;
  2169.   {$EXTERNALSYM CERT_INFO}
  2170.   TCertInfo = CERT_INFO;
  2171.   PCertInfo = PCERT_INFO;
  2172. //+-------------------------------------------------------------------------
  2173. //  Certificate versions
  2174. //--------------------------------------------------------------------------
  2175. const
  2176.   CERT_V1 = 0;
  2177.   {$EXTERNALSYM CERT_V1}
  2178.   CERT_V2 = 1;
  2179.   {$EXTERNALSYM CERT_V2}
  2180.   CERT_V3 = 2;
  2181.   {$EXTERNALSYM CERT_V3}
  2182. //+-------------------------------------------------------------------------
  2183. //  Certificate Information Flags
  2184. //--------------------------------------------------------------------------
  2185.   CERT_INFO_VERSION_FLAG                 = 1;
  2186.   {$EXTERNALSYM CERT_INFO_VERSION_FLAG}
  2187.   CERT_INFO_SERIAL_NUMBER_FLAG           = 2;
  2188.   {$EXTERNALSYM CERT_INFO_SERIAL_NUMBER_FLAG}
  2189.   CERT_INFO_SIGNATURE_ALGORITHM_FLAG     = 3;
  2190.   {$EXTERNALSYM CERT_INFO_SIGNATURE_ALGORITHM_FLAG}
  2191.   CERT_INFO_ISSUER_FLAG                  = 4;
  2192.   {$EXTERNALSYM CERT_INFO_ISSUER_FLAG}
  2193.   CERT_INFO_NOT_BEFORE_FLAG              = 5;
  2194.   {$EXTERNALSYM CERT_INFO_NOT_BEFORE_FLAG}
  2195.   CERT_INFO_NOT_AFTER_FLAG               = 6;
  2196.   {$EXTERNALSYM CERT_INFO_NOT_AFTER_FLAG}
  2197.   CERT_INFO_SUBJECT_FLAG                 = 7;
  2198.   {$EXTERNALSYM CERT_INFO_SUBJECT_FLAG}
  2199.   CERT_INFO_SUBJECT_PUBLIC_KEY_INFO_FLAG = 8;
  2200.   {$EXTERNALSYM CERT_INFO_SUBJECT_PUBLIC_KEY_INFO_FLAG}
  2201.   CERT_INFO_ISSUER_UNIQUE_ID_FLAG        = 9;
  2202.   {$EXTERNALSYM CERT_INFO_ISSUER_UNIQUE_ID_FLAG}
  2203.   CERT_INFO_SUBJECT_UNIQUE_ID_FLAG       = 10;
  2204.   {$EXTERNALSYM CERT_INFO_SUBJECT_UNIQUE_ID_FLAG}
  2205.   CERT_INFO_EXTENSION_FLAG               = 11;
  2206.   {$EXTERNALSYM CERT_INFO_EXTENSION_FLAG}
  2207. //+-------------------------------------------------------------------------
  2208. //  An entry in a CRL
  2209. //
  2210. //  The Extension BLOBs are the encoded representation of the information.
  2211. //--------------------------------------------------------------------------
  2212. type
  2213.   PCRL_ENTRY = ^CRL_ENTRY;
  2214.   {$EXTERNALSYM PCRL_ENTRY}
  2215.   _CRL_ENTRY = record
  2216.     SerialNumber: CRYPT_INTEGER_BLOB;
  2217.     RevocationDate: FILETIME;
  2218.     cExtension: DWORD;
  2219.     rgExtension: PCERT_EXTENSION;
  2220.   end;
  2221.   {$EXTERNALSYM _CRL_ENTRY}
  2222.   CRL_ENTRY = _CRL_ENTRY;
  2223.   {$EXTERNALSYM CRL_ENTRY}
  2224.   TCrlEntry = CRL_ENTRY;
  2225.   PCrlEntry = PCRL_ENTRY;
  2226. //+-------------------------------------------------------------------------
  2227. //  Information stored in a CRL
  2228. //
  2229. //  The Issuer, Algorithm and Extension BLOBs are the encoded
  2230. //  representation of the information.
  2231. //--------------------------------------------------------------------------
  2232.   PCRL_INFO = ^CRL_INFO;
  2233.   {$EXTERNALSYM PCRL_INFO}
  2234.   _CRL_INFO = record
  2235.     dwVersion: DWORD;
  2236.     SignatureAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  2237.     Issuer: CERT_NAME_BLOB;
  2238.     ThisUpdate: FILETIME;
  2239.     NextUpdate: FILETIME;
  2240.     cCRLEntry: DWORD;
  2241.     rgCRLEntry: PCRL_ENTRY;
  2242.     cExtension: DWORD;
  2243.     rgExtension: PCERT_EXTENSION;
  2244.   end;
  2245.   {$EXTERNALSYM _CRL_INFO}
  2246.   CRL_INFO = _CRL_INFO;
  2247.   {$EXTERNALSYM CRL_INFO}
  2248.   TCrlInfo = CRL_INFO;
  2249.   PCrlInfo = PCRL_INFO;
  2250. //+-------------------------------------------------------------------------
  2251. //  CRL versions
  2252. //--------------------------------------------------------------------------
  2253. const
  2254.   CRL_V1 = 0;
  2255.   {$EXTERNALSYM CRL_V1}
  2256.   CRL_V2 = 1;
  2257.   {$EXTERNALSYM CRL_V2}
  2258. //+-------------------------------------------------------------------------
  2259. //  Information stored in a certificate request
  2260. //
  2261. //  The Subject, Algorithm, PublicKey and Attribute BLOBs are the encoded
  2262. //  representation of the information.
  2263. //--------------------------------------------------------------------------
  2264. type
  2265.   PCERT_REQUEST_INFO = ^CERT_REQUEST_INFO;
  2266.   {$EXTERNALSYM PCERT_REQUEST_INFO}
  2267.   _CERT_REQUEST_INFO = record
  2268.     dwVersion: DWORD;
  2269.     Subject: CERT_NAME_BLOB;
  2270.     SubjectPublicKeyInfo: CERT_PUBLIC_KEY_INFO;
  2271.     cAttribute: DWORD;
  2272.     rgAttribute: PCRYPT_ATTRIBUTE;
  2273.   end;
  2274.   {$EXTERNALSYM _CERT_REQUEST_INFO}
  2275.   CERT_REQUEST_INFO = _CERT_REQUEST_INFO;
  2276.   {$EXTERNALSYM CERT_REQUEST_INFO}
  2277.   TCertRequestInfo = CERT_REQUEST_INFO;
  2278.   PCertRequestInfo = PCERT_REQUEST_INFO;
  2279. //+-------------------------------------------------------------------------
  2280. //  Certificate Request versions
  2281. //--------------------------------------------------------------------------
  2282. const
  2283.   CERT_REQUEST_V1 = 0;
  2284.   {$EXTERNALSYM CERT_REQUEST_V1}
  2285. //+-------------------------------------------------------------------------
  2286. //  Information stored in Netscape's Keygen request
  2287. //--------------------------------------------------------------------------
  2288. type
  2289.   PCERT_KEYGEN_REQUEST_INFO = ^CERT_KEYGEN_REQUEST_INFO;
  2290.   {$EXTERNALSYM PCERT_KEYGEN_REQUEST_INFO}
  2291.   _CERT_KEYGEN_REQUEST_INFO = record
  2292.     dwVersion: DWORD;
  2293.     SubjectPublicKeyInfo: CERT_PUBLIC_KEY_INFO;
  2294.     pwszChallengeString: LPWSTR; // encoded as IA5
  2295.   end;
  2296.   {$EXTERNALSYM _CERT_KEYGEN_REQUEST_INFO}
  2297.   CERT_KEYGEN_REQUEST_INFO = _CERT_KEYGEN_REQUEST_INFO;
  2298.   {$EXTERNALSYM CERT_KEYGEN_REQUEST_INFO}
  2299.   TCertKeygenRequestInfo = CERT_KEYGEN_REQUEST_INFO;
  2300.   PCertKeygenRequestInfo = PCERT_KEYGEN_REQUEST_INFO;
  2301. const
  2302.   CERT_KEYGEN_REQUEST_V1 = 0;
  2303.   {$EXTERNALSYM CERT_KEYGEN_REQUEST_V1}
  2304. //+-------------------------------------------------------------------------
  2305. //  Certificate, CRL, Certificate Request or Keygen Request Signed Content
  2306. //
  2307. //  The "to be signed" encoded content plus its signature. The ToBeSigned
  2308. //  is the encoded CERT_INFO, CRL_INFO, CERT_REQUEST_INFO or
  2309. //  CERT_KEYGEN_REQUEST_INFO.
  2310. //--------------------------------------------------------------------------
  2311. type
  2312.   PCERT_SIGNED_CONTENT_INFO = ^CERT_SIGNED_CONTENT_INFO;
  2313.   {$EXTERNALSYM PCERT_SIGNED_CONTENT_INFO}
  2314.   _CERT_SIGNED_CONTENT_INFO = record
  2315.     ToBeSigned: CRYPT_DER_BLOB;
  2316.     SignatureAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  2317.     Signature: CRYPT_BIT_BLOB;
  2318.   end;
  2319.   {$EXTERNALSYM _CERT_SIGNED_CONTENT_INFO}
  2320.   CERT_SIGNED_CONTENT_INFO = _CERT_SIGNED_CONTENT_INFO;
  2321.   {$EXTERNALSYM CERT_SIGNED_CONTENT_INFO}
  2322.   TCertSignedContentInfo = CERT_SIGNED_CONTENT_INFO;
  2323.   PCertSignedContentInfo = PCERT_SIGNED_CONTENT_INFO;
  2324. //+-------------------------------------------------------------------------
  2325. //  Certificate Trust List (CTL)
  2326. //--------------------------------------------------------------------------
  2327. //+-------------------------------------------------------------------------
  2328. //  CTL Usage. Also used for EnhancedKeyUsage extension.
  2329. //--------------------------------------------------------------------------
  2330.   PCTL_USAGE = ^CTL_USAGE;
  2331.   {$EXTERNALSYM PCTL_USAGE}
  2332.   _CTL_USAGE = record
  2333.     cUsageIdentifier: DWORD;
  2334.     rgpszUsageIdentifier: LPSTR; // array of pszObjId
  2335.   end;
  2336.   {$EXTERNALSYM _CTL_USAGE}
  2337.   CTL_USAGE = _CTL_USAGE;
  2338.   {$EXTERNALSYM CTL_USAGE}
  2339.   TCtlUsage = CTL_USAGE;
  2340.   PCtlUsage = PCTL_USAGE;
  2341.   CERT_ENHKEY_USAGE = CTL_USAGE;
  2342.   {$EXTERNALSYM CERT_ENHKEY_USAGE}
  2343.   PCERT_ENHKEY_USAGE = PCTL_USAGE;
  2344.   {$EXTERNALSYM PCERT_ENHKEY_USAGE}
  2345. //+-------------------------------------------------------------------------
  2346. //  An entry in a CTL
  2347. //--------------------------------------------------------------------------
  2348.   PCTL_ENTRY = ^CTL_ENTRY;
  2349.   {$EXTERNALSYM PCTL_ENTRY}
  2350.   _CTL_ENTRY = record
  2351.     SubjectIdentifier: CRYPT_DATA_BLOB; // For example, its hash
  2352.     cAttribute: DWORD;
  2353.     rgAttribute: PCRYPT_ATTRIBUTE; // OPTIONAL
  2354.   end;
  2355.   {$EXTERNALSYM _CTL_ENTRY}
  2356.   CTL_ENTRY = _CTL_ENTRY;
  2357.   {$EXTERNALSYM CTL_ENTRY}
  2358.   TCtlEntry = CTL_ENTRY;
  2359.   PCtlEntry = PCTL_ENTRY;
  2360. //+-------------------------------------------------------------------------
  2361. //  Information stored in a CTL
  2362. //--------------------------------------------------------------------------
  2363.   PCTL_INFO = ^CTL_INFO;
  2364.   {$EXTERNALSYM PCTL_INFO}
  2365.   _CTL_INFO = record
  2366.     dwVersion: DWORD;
  2367.     SubjectUsage: CTL_USAGE;
  2368.     ListIdentifier: CRYPT_DATA_BLOB; // OPTIONAL
  2369.     SequenceNumber: CRYPT_INTEGER_BLOB; // OPTIONAL
  2370.     ThisUpdate: FILETIME;
  2371.     NextUpdate: FILETIME; // OPTIONAL
  2372.     SubjectAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
  2373.     cCTLEntry: DWORD;
  2374.     rgCTLEntry: PCTL_ENTRY; // OPTIONAL
  2375.     cExtension: DWORD;
  2376.     rgExtension: PCERT_EXTENSION; // OPTIONAL
  2377.   end;
  2378.   {$EXTERNALSYM _CTL_INFO}
  2379.   CTL_INFO = _CTL_INFO;
  2380.   {$EXTERNALSYM CTL_INFO}
  2381.   TCtlInfo = CTL_INFO;
  2382.   PCtlInfo = PCTL_INFO;
  2383. //+-------------------------------------------------------------------------
  2384. //  CTL versions
  2385. //--------------------------------------------------------------------------
  2386. const
  2387.   CTL_V1 = 0;
  2388.   {$EXTERNALSYM CTL_V1}
  2389. //+-------------------------------------------------------------------------
  2390. //  TimeStamp Request
  2391. //
  2392. //  The pszTimeStamp is the OID for the Time type requested
  2393. //  The pszContentType is the Content Type OID for the content, usually DATA
  2394. //  The Content is a un-decoded blob
  2395. //--------------------------------------------------------------------------
  2396. type
  2397.   PCRYPT_TIME_STAMP_REQUEST_INFO = ^CRYPT_TIME_STAMP_REQUEST_INFO;
  2398.   {$EXTERNALSYM PCRYPT_TIME_STAMP_REQUEST_INFO}
  2399.   _CRYPT_TIME_STAMP_REQUEST_INFO = record
  2400.     pszTimeStampAlgorithm: LPSTR; // pszObjId
  2401.     pszContentType: LPSTR; // pszObjId
  2402.     Content: CRYPT_OBJID_BLOB;
  2403.     cAttribute: DWORD;
  2404.     rgAttribute: PCRYPT_ATTRIBUTE;
  2405.   end;
  2406.   {$EXTERNALSYM _CRYPT_TIME_STAMP_REQUEST_INFO}
  2407.   CRYPT_TIME_STAMP_REQUEST_INFO = _CRYPT_TIME_STAMP_REQUEST_INFO;
  2408.   {$EXTERNALSYM CRYPT_TIME_STAMP_REQUEST_INFO}
  2409.   TCryptTimeStampRequestInfo = CRYPT_TIME_STAMP_REQUEST_INFO;
  2410.   PCryptTimeStampRequestInfo = PCRYPT_TIME_STAMP_REQUEST_INFO;
  2411. //+-------------------------------------------------------------------------
  2412. //  Name Value Attribute
  2413. //--------------------------------------------------------------------------
  2414.   PCRYPT_ENROLLMENT_NAME_VALUE_PAIR = ^CRYPT_ENROLLMENT_NAME_VALUE_PAIR;
  2415.   {$EXTERNALSYM PCRYPT_ENROLLMENT_NAME_VALUE_PAIR}
  2416.   _CRYPT_ENROLLMENT_NAME_VALUE_PAIR = record
  2417.     pwszName: LPWSTR;
  2418.     pwszValue: LPWSTR;
  2419.   end;
  2420.   {$EXTERNALSYM _CRYPT_ENROLLMENT_NAME_VALUE_PAIR}
  2421.   CRYPT_ENROLLMENT_NAME_VALUE_PAIR = _CRYPT_ENROLLMENT_NAME_VALUE_PAIR;
  2422.   {$EXTERNALSYM CRYPT_ENROLLMENT_NAME_VALUE_PAIR}
  2423.   TCryptEnrollmentNameValuePair = CRYPT_ENROLLMENT_NAME_VALUE_PAIR;
  2424.   PCryptEnrollmentNameValuePair = PCRYPT_ENROLLMENT_NAME_VALUE_PAIR;
  2425. //+-------------------------------------------------------------------------
  2426. //  CSP Provider
  2427. //--------------------------------------------------------------------------
  2428.   PCRYPT_CSP_PROVIDER = ^CRYPT_CSP_PROVIDER;
  2429.   {$EXTERNALSYM PCRYPT_CSP_PROVIDER}
  2430.   _CRYPT_CSP_PROVIDER = record
  2431.     dwKeySpec: DWORD;
  2432.     pwszProviderName: LPWSTR;
  2433.     Signature: CRYPT_BIT_BLOB;
  2434.   end;
  2435.   {$EXTERNALSYM _CRYPT_CSP_PROVIDER}
  2436.   CRYPT_CSP_PROVIDER = _CRYPT_CSP_PROVIDER;
  2437.   {$EXTERNALSYM CRYPT_CSP_PROVIDER}
  2438.   TCryptCspProvider = CRYPT_CSP_PROVIDER;
  2439.   PCryptCspProvider = PCRYPT_CSP_PROVIDER;
  2440. //+-------------------------------------------------------------------------
  2441. //  Certificate and Message encoding types
  2442. //
  2443. //  The encoding type is a DWORD containing both the certificate and message
  2444. //  encoding types. The certificate encoding type is stored in the LOWORD.
  2445. //  The message encoding type is stored in the HIWORD. Some functions or
  2446. //  structure fields require only one of the encoding types. The following
  2447. //  naming convention is used to indicate which encoding type(s) are
  2448. //  required:
  2449. //      dwEncodingType              (both encoding types are required)
  2450. //      dwMsgAndCertEncodingType    (both encoding types are required)
  2451. //      dwMsgEncodingType           (only msg encoding type is required)
  2452. //      dwCertEncodingType          (only cert encoding type is required)
  2453. //
  2454. //  Its always acceptable to specify both.
  2455. //--------------------------------------------------------------------------
  2456. const
  2457.   CERT_ENCODING_TYPE_MASK = $0000FFFF;
  2458.   {$EXTERNALSYM CERT_ENCODING_TYPE_MASK}
  2459.   CMSG_ENCODING_TYPE_MASK = DWORD($FFFF0000);
  2460.   {$EXTERNALSYM CMSG_ENCODING_TYPE_MASK}
  2461. function GET_CERT_ENCODING_TYPE(X: DWORD): DWORD;
  2462. {$EXTERNALSYM GET_CERT_ENCODING_TYPE}
  2463. function GET_CMSG_ENCODING_TYPE(X: DWORD): DWORD;
  2464. {$EXTERNALSYM GET_CMSG_ENCODING_TYPE}
  2465. const
  2466.   CRYPT_ASN_ENCODING  = $00000001;
  2467.   {$EXTERNALSYM CRYPT_ASN_ENCODING}
  2468.   CRYPT_NDR_ENCODING  = $00000002;
  2469.   {$EXTERNALSYM CRYPT_NDR_ENCODING}
  2470.   X509_ASN_ENCODING   = $00000001;
  2471.   {$EXTERNALSYM X509_ASN_ENCODING}
  2472.   X509_NDR_ENCODING   = $00000002;
  2473.   {$EXTERNALSYM X509_NDR_ENCODING}
  2474.   PKCS_7_ASN_ENCODING = $00010000;
  2475.   {$EXTERNALSYM PKCS_7_ASN_ENCODING}
  2476.   PKCS_7_NDR_ENCODING = $00020000;
  2477.   {$EXTERNALSYM PKCS_7_NDR_ENCODING}
  2478. //+-------------------------------------------------------------------------
  2479. //  format the specified data structure according to the certificate
  2480. //  encoding type.
  2481. //
  2482. //  The default behavior of CryptFormatObject is to return single line
  2483. //  display of the encoded data, that is, each subfield will be concatenated with
  2484. //  a ", " on one line.  If user prefers to display the data in multiple line,
  2485. //  set the flag CRYPT_FORMAT_STR_MULTI_LINE, that is, each subfield will be displayed
  2486. //  on a seperate line.
  2487. //
  2488. //  If there is no formatting routine installed or registered
  2489. //  for the lpszStructType, the hex dump of the encoded BLOB will be returned.
  2490. //  User can set the flag CRYPT_FORMAT_STR_NO_HEX to disable the hex dump.
  2491. //--------------------------------------------------------------------------
  2492. function CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType: DWORD;
  2493.   pFormatStruct: Pointer; lpszStructType: LPCSTR; pbEncoded: LPBYTE;
  2494.     cbEncoded: DWORD; pbFormat: Pointer; var pcbFormat: DWORD): BOOL; stdcall;
  2495. {$EXTERNALSYM CryptFormatObject}
  2496. //-------------------------------------------------------------------------
  2497. // constants for dwFormatStrType of function CryptFormatObject
  2498. //-------------------------------------------------------------------------
  2499. const
  2500.   CRYPT_FORMAT_STR_MULTI_LINE = $0001;
  2501.   {$EXTERNALSYM CRYPT_FORMAT_STR_MULTI_LINE}
  2502.   CRYPT_FORMAT_STR_NO_HEX     = $0010;
  2503.   {$EXTERNALSYM CRYPT_FORMAT_STR_NO_HEX}
  2504. //-------------------------------------------------------------------------
  2505. // constants for dwFormatType of function CryptFormatObject
  2506. // when format X509_NAME or X509_UNICODE_NAME
  2507. //-------------------------------------------------------------------------
  2508. // Just get the simple string
  2509.   CRYPT_FORMAT_SIMPLE = $0001;
  2510.   {$EXTERNALSYM CRYPT_FORMAT_SIMPLE}
  2511. //Put an attribute name infront of the attribute
  2512. //such as "O=Microsoft,DN=xiaohs"
  2513.   CRYPT_FORMAT_X509 = $0002;
  2514.   {$EXTERNALSYM CRYPT_FORMAT_X509}
  2515. //Put an OID infront of the simple string, such as
  2516. //"2.5.4.22=Microsoft,2.5.4.3=xiaohs"
  2517.   CRYPT_FORMAT_OID = $0004;
  2518.   {$EXTERNALSYM CRYPT_FORMAT_OID}
  2519. //Put a ";" between each RDN.  The default is ","
  2520.   CRYPT_FORMAT_RDN_SEMICOLON = $0100;
  2521.   {$EXTERNALSYM CRYPT_FORMAT_RDN_SEMICOLON}
  2522. //Put a "n" between each RDN.
  2523.   CRYPT_FORMAT_RDN_CRLF = $0200;
  2524.   {$EXTERNALSYM CRYPT_FORMAT_RDN_CRLF}
  2525. //Unquote the DN value, which is quoated by default va the following
  2526. //rules: if the DN contains leading or trailing
  2527. //white space or one of the following characters: ",", "+", "=",
  2528. //""", "n",  "<", ">", "#" or ";". The quoting character is ".
  2529. //If the DN Value contains a " it is double quoted ("").
  2530.   CRYPT_FORMAT_RDN_UNQUOTE = $0400;
  2531.   {$EXTERNALSYM CRYPT_FORMAT_RDN_UNQUOTE}
  2532. //reverse the order of the RDNs before converting to the string
  2533.   CRYPT_FORMAT_RDN_REVERSE = $0800;
  2534.   {$EXTERNALSYM CRYPT_FORMAT_RDN_REVERSE}
  2535. //-------------------------------------------------------------------------
  2536. //  contants dwFormatType of function CryptFormatObject when format a DN.:
  2537. //
  2538. //  The following three values are defined in the section above:
  2539. //  CRYPT_FORMAT_SIMPLE:    Just a simple string
  2540. //                          such as  "Microsoft+xiaohs+NT"
  2541. //  CRYPT_FORMAT_X509       Put an attribute name infront of the attribute
  2542. //                          such as "O=Microsoft+xiaohs+NT"
  2543. //
  2544. //  CRYPT_FORMAT_OID        Put an OID infront of the simple string,
  2545. //                          such as "2.5.4.22=Microsoft+xiaohs+NT"
  2546. //
  2547. //  Additional values are defined as following:
  2548. //----------------------------------------------------------------------------
  2549. //Put a "," between each value.  Default is "+"
  2550.   CRYPT_FORMAT_COMMA = $1000;
  2551.   {$EXTERNALSYM CRYPT_FORMAT_COMMA}
  2552. //Put a ";" between each value
  2553.   CRYPT_FORMAT_SEMICOLON = CRYPT_FORMAT_RDN_SEMICOLON;
  2554.   {$EXTERNALSYM CRYPT_FORMAT_SEMICOLON}
  2555. //Put a "n" between each value
  2556.   CRYPT_FORMAT_CRLF = CRYPT_FORMAT_RDN_CRLF;
  2557.   {$EXTERNALSYM CRYPT_FORMAT_CRLF}
  2558. //+-------------------------------------------------------------------------
  2559. //  Encode / decode the specified data structure according to the certificate
  2560. //  encoding type.
  2561. //
  2562. //  See below for a list of the predefined data structures.
  2563. //--------------------------------------------------------------------------
  2564. type
  2565.   PFN_CRYPT_ALLOC = function (cbSize: size_t): LPVOID; stdcall;
  2566.   {$EXTERNALSYM PFN_CRYPT_ALLOC}
  2567.   PFN_CRYPT_FREE = procedure (pv: LPVOID); stdcall;
  2568.   {$EXTERNALSYM PFN_CRYPT_FREE}
  2569.   PCRYPT_ENCODE_PARA = ^CRYPT_ENCODE_PARA;
  2570.   {$EXTERNALSYM PCRYPT_ENCODE_PARA}
  2571.   _CRYPT_ENCODE_PARA = record
  2572.     cbSize: DWORD;
  2573.     pfnAlloc: PFN_CRYPT_ALLOC; // OPTIONAL
  2574.     pfnFree: PFN_CRYPT_FREE; // OPTIONAL
  2575.   end;
  2576.   {$EXTERNALSYM _CRYPT_ENCODE_PARA}
  2577.   CRYPT_ENCODE_PARA = _CRYPT_ENCODE_PARA;
  2578.   {$EXTERNALSYM CRYPT_ENCODE_PARA}
  2579.   TCryptEncodePara = CRYPT_ENCODE_PARA;
  2580.   PCryptEncodePara = PCRYPT_ENCODE_PARA;
  2581. function CryptEncodeObjectEx(dwCertEncodingType: DWORD; lpszStructType: LPCSTR;
  2582.   pvStructInfo: Pointer; dwFlags: DWORD; pEncodePara: PCRYPT_ENCODE_PARA;
  2583.   pvEncoded: Pointer; var pcbEncoded: DWORD): BOOL; stdcall;
  2584. {$EXTERNALSYM CryptEncodeObjectEx}
  2585. function CryptEncodeObject(dwCertEncodingType: DWORD; lpszStructType: LPCSTR;
  2586.   pvStructInfo: Pointer; pbEncoded: LPBYTE; var pcbEncoded: DWORD): BOOL; stdcall;
  2587. {$EXTERNALSYM CryptEncodeObject}
  2588. // By default the signature bytes are reversed. The following flag can
  2589. // be set to inhibit the byte reversal.
  2590. //
  2591. // This flag is applicable to
  2592. //      X509_CERT_TO_BE_SIGNED
  2593. const
  2594.   CRYPT_ENCODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG = $8;
  2595.   {$EXTERNALSYM CRYPT_ENCODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG}
  2596. //  When the following flag is set the called encode function allocates
  2597. //  memory for the encoded bytes. A pointer to the allocated bytes
  2598. //  is returned in pvEncoded. If pEncodePara or pEncodePara->pfnAlloc is
  2599. //  NULL, then, LocalAlloc is called for the allocation and LocalFree must
  2600. //  be called to do the free. Otherwise, pEncodePara->pfnAlloc is called
  2601. //  for the allocation.
  2602. //
  2603. //  *pcbEncoded is ignored on input and updated with the length of the
  2604. //  allocated, encoded bytes.
  2605. //
  2606. //  If pfnAlloc is set, then, pfnFree should also be set.
  2607.   CRYPT_ENCODE_ALLOC_FLAG = $8000;
  2608.   {$EXTERNALSYM CRYPT_ENCODE_ALLOC_FLAG}
  2609. //  The following flag is applicable when encoding X509_UNICODE_NAME.
  2610. //  When set, CERT_RDN_T61_STRING is selected instead of
  2611. //  CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF
  2612.   CRYPT_UNICODE_NAME_ENCODE_ENABLE_T61_UNICODE_FLAG = CERT_RDN_ENABLE_T61_UNICODE_FLAG;
  2613.   {$EXTERNALSYM CRYPT_UNICODE_NAME_ENCODE_ENABLE_T61_UNICODE_FLAG}