⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cryptlib.bas

📁 cryptlib是功能强大的安全工具集。允许开发人员快速在自己的软件中集成加密和认证服务。
💻 BAS
📖 第 1 页 / 共 5 页
字号:
' The maximum hash size - 256 bits   Public Const CRYPT_MAX_HASHSIZE As Long = 32' The maximum size of a text string (e.g.key owner name)   Public Const CRYPT_MAX_TEXTSIZE As Long = 64'  A magic value indicating that the default setting for this parameter'  should be used   Public Const CRYPT_USE_DEFAULT As Long = -10' A magic value for unused parameters   Public Const CRYPT_UNUSED As Long = -11' Whether the PKC key is a public or private key   Public Const CRYPT_KEYTYPE_PRIVATE As Long = 0  Public Const CRYPT_KEYTYPE_PUBLIC As Long = 1' The type of information polling to perform to get random seed information   Public Const CRYPT_RANDOM_FASTPOLL As Long = -10  Public Const CRYPT_RANDOM_SLOWPOLL As Long = -11' Cursor positioning codes for certificate/CRL extensions   Public Const CRYPT_CURSOR_FIRST As Long = -20  Public Const CRYPT_CURSOR_PREVIOUS As Long = -21  Public Const CRYPT_CURSOR_NEXT As Long = -22  Public Const CRYPT_CURSOR_LAST As Long = -23' Keyset open options Public Enum CRYPT_KEYOPT_TYPE    CRYPT_KEYOPT_NONE               ' No options     CRYPT_KEYOPT_READONLY           ' Open keyset in read-only mode     CRYPT_KEYOPT_CREATE             ' Create a new keyset     CRYPT_KEYOPT_LAST               ' Last possible key option type     End Enum' The various cryptlib objects - these are just integer handles REM  CRYPT_CERTIFICATE = LongREM  CRYPT_CONTEXT = LongREM  CRYPT_DEVICE = LongREM  CRYPT_ENVELOPE = LongREM  CRYPT_KEYSET = LongREM  CRYPT_SESSION = LongREM  CRYPT_USER = Long'  Sometimes we don't know the exact type of a cryptlib object, so we use a'  generic handle type to identify it REM  CRYPT_HANDLE = Long'****************************************************************************'*                                                                           *'*                           Encryption Data Structures                      *'*                                                                           *'****************************************************************************' Results returned from the capability query Public Type CRYPT_QUERY_INFO     ' Algorithm information     algoName(CRYPT_MAX_TEXTSIZE-1) As Byte' Algorithm name     blockSize As Long                  ' Block size of the algorithm     minKeySize As Long                 ' Minimum key size in bytes     keySize As Long                    ' Recommended key size in bytes     maxKeySize As Long                 ' Maximum key size in bytes     End Type'  Results returned from the encoded object query.  These provide'  information on the objects created by cryptExportKey()/'  cryptCreateSignature() Public Type CRYPT_OBJECT_INFO     ' The object type     objectType As CRYPT_OBJECT_TYPE    ' The encryption algorithm and mode     cryptAlgo As CRYPT_ALGO_TYPE    cryptMode As CRYPT_MODE_TYPE    ' The hash algorithm for Signature objects     hashAlgo As CRYPT_ALGO_TYPE    ' The salt for derived keys     salt(CRYPT_MAX_HASHSIZE-1) As Byte    saltSize As Long    End Type'  Key information for the public-key encryption algorithms.  These fields'  are not accessed directly, but can be manipulated with the init/set/'  destroyComponents() macros Public Type CRYPT_PKCINFO_RSA     ' Status information     isPublicKey As Long            ' Whether this is a public or private key     ' Public components     n(CRYPT_MAX_PKCSIZE-1) As Byte   ' Modulus     nLen As Long                   ' Length of modulus in bits     e(CRYPT_MAX_PKCSIZE-1) As Byte   ' Public exponent     eLen As Long                   ' Length of public exponent in bits     ' Private components     d(CRYPT_MAX_PKCSIZE-1) As Byte   ' Private exponent     dLen As Long                   ' Length of private exponent in bits     p(CRYPT_MAX_PKCSIZE-1) As Byte   ' Prime factor 1     pLen As Long                   ' Length of prime factor 1 in bits     q(CRYPT_MAX_PKCSIZE-1) As Byte   ' Prime factor 2     qLen As Long                   ' Length of prime factor 2 in bits     u(CRYPT_MAX_PKCSIZE-1) As Byte   ' Mult.inverse of q, mod p     uLen As Long                   ' Length of private exponent in bits     e1(CRYPT_MAX_PKCSIZE-1) As Byte  ' Private exponent 1 (PKCS)     e1Len As Long                  ' Length of private exponent in bits     e2(CRYPT_MAX_PKCSIZE-1) As Byte  ' Private exponent 2 (PKCS)     e2Len As Long                  ' Length of private exponent in bits     End TypePublic Type CRYPT_PKCINFO_DLP     ' Status information     isPublicKey As Long            ' Whether this is a public or private key     ' Public components     p(CRYPT_MAX_PKCSIZE-1) As Byte   ' Prime modulus     pLen As Long                   ' Length of prime modulus in bits     q(CRYPT_MAX_PKCSIZE-1) As Byte   ' Prime divisor     qLen As Long                   ' Length of prime divisor in bits     g(CRYPT_MAX_PKCSIZE-1) As Byte   ' h^( ( p - 1 ) / q ) mod p     gLen As Long                   ' Length of g in bits     y(CRYPT_MAX_PKCSIZE-1) As Byte   ' Public random integer     yLen As Long                   ' Length of public integer in bits     ' Private components     x(CRYPT_MAX_PKCSIZE-1) As Byte   ' Private random integer     xLen As Long                   ' Length of private integer in bits     End Type'  Macros to initialise and destroy the structure that stores the components'  of a public key ' C-macro not translated to Visual Basic code: '   #define cryptInitComponents( componentInfo, componentKeyType ) '    { memset( ( componentInfo ), 0, sizeof( *componentInfo ) ); '      ( componentInfo )->isPublicKey = ( ( componentKeyType ) ? 1 : 0 ); }'' C-macro not translated to Visual Basic code: '   #define cryptDestroyComponents( componentInfo ) '    memset( ( componentInfo ), 0, sizeof( *componentInfo ) )'' Macros to set a component of a public key ' C-macro not translated to Visual Basic code: '   #define cryptSetComponent( destination, source, length ) '    { memcpy( ( destination ), ( source ), ( ( length ) + 7 ) >> 3 ); '      ( destination##Len ) = length; }''****************************************************************************'*                                                                           *'*                               Status Codes                                *'*                                                                           *'****************************************************************************' No error in function call   Public Const CRYPT_OK As Long = 0   ' No error ' Error in parameters passed to function   Public Const CRYPT_ERROR_PARAM1 As Long = -1  ' Bad argument, parameter 1   Public Const CRYPT_ERROR_PARAM2 As Long = -2  ' Bad argument, parameter 2   Public Const CRYPT_ERROR_PARAM3 As Long = -3  ' Bad argument, parameter 3   Public Const CRYPT_ERROR_PARAM4 As Long = -4  ' Bad argument, parameter 4   Public Const CRYPT_ERROR_PARAM5 As Long = -5  ' Bad argument, parameter 5   Public Const CRYPT_ERROR_PARAM6 As Long = -6  ' Bad argument, parameter 6   Public Const CRYPT_ERROR_PARAM7 As Long = -7  ' Bad argument, parameter 7 ' Errors due to insufficient resources   Public Const CRYPT_ERROR_MEMORY As Long = -10 ' Out of memory   Public Const CRYPT_ERROR_NOTINITED As Long = -11 ' Data has not been initialised   Public Const CRYPT_ERROR_INITED As Long = -12 ' Data has already been init'd   Public Const CRYPT_ERROR_NOSECURE As Long = -13 ' Opn.not avail.at requested sec.level   Public Const CRYPT_ERROR_RANDOM As Long = -14 ' No reliable random data available   Public Const CRYPT_ERROR_FAILED As Long = -15 ' Operation failed ' Security violations   Public Const CRYPT_ERROR_NOTAVAIL As Long = -20 ' This type of opn.not available   Public Const CRYPT_ERROR_PERMISSION As Long = -21 ' No permiss.to perform this operation   Public Const CRYPT_ERROR_WRONGKEY As Long = -22 ' Incorrect key used to decrypt data   Public Const CRYPT_ERROR_INCOMPLETE As Long = -23 ' Operation incomplete/still in progress   Public Const CRYPT_ERROR_COMPLETE As Long = -24 ' Operation complete/can't continue   Public Const CRYPT_ERROR_TIMEOUT As Long = -25 ' Operation timed out before completion   Public Const CRYPT_ERROR_INVALID As Long = -26 ' Invalid/inconsistent information   Public Const CRYPT_ERROR_SIGNALLED As Long = -27 ' Resource destroyed by extnl.event ' High-level function errors   Public Const CRYPT_ERROR_OVERFLOW As Long = -30 ' Resources/space exhausted   Public Const CRYPT_ERROR_UNDERFLOW As Long = -31 ' Not enough data available   Public Const CRYPT_ERROR_BADDATA As Long = -32 ' Bad/unrecognised data format   Public Const CRYPT_ERROR_SIGNATURE As Long = -33 ' Signature/integrity check failed ' Data access function errors   Public Const CRYPT_ERROR_OPEN As Long = -40 ' Cannot open object   Public Const CRYPT_ERROR_READ As Long = -41 ' Cannot read item from object   Public Const CRYPT_ERROR_WRITE As Long = -42 ' Cannot write item to object   Public Const CRYPT_ERROR_NOTFOUND As Long = -43 ' Requested item not found in object   Public Const CRYPT_ERROR_DUPLICATE As Long = -44 ' Item already present in object ' Data enveloping errors   Public Const CRYPT_ENVELOPE_RESOURCE As Long = -50 ' Need resource to proceed ' Macros to examine return values ' C-macro not translated to Visual Basic code: '   #define cryptStatusError( status )  ( ( status ) < CRYPT_OK )'' C-macro not translated to Visual Basic code: '   #define cryptStatusOK( status )     ( ( status ) == CRYPT_OK )''****************************************************************************'*                                                                           *'*                                   General Functions                       *'*                                                                           *'****************************************************************************' The following is necessary to stop C++ name mangling ' Initialise and shut down cryptlib Public Declare Function cryptInit Lib "CL32.DLL" () As LongPublic Declare Function cryptEnd Lib "CL32.DLL" () As Long' Query cryptlibs capabilities Public Declare Function cryptQueryCapability Lib "CL32.DLL" ( ByVal cryptAlgo As CRYPT_ALGO_TYPE, _ ByRef cryptQueryInfo As CRYPT_QUERY_INFO) As Long' Create and destroy an encryption context Public Declare Function cryptCreateContext Lib "CL32.DLL" ( ByRef cryptContext As Long, _ ByVal cryptUser As Long, _ ByVal cryptAlgo As CRYPT_ALGO_TYPE) As LongPublic Declare Function cryptDestroyContext Lib "CL32.DLL" ( ByVal cryptContext As Long) As Long' Generic "destroy an object" function Public Declare Function cryptDestroyObject Lib "CL32.DLL" ( ByVal cryptObject As Long) As Long' Generate a key into a context Public Declare Function cryptGenerateKey Lib "CL32.DLL" ( ByVal cryptContext As Long) As LongPublic Declare Function cryptGenerateKeyAsync Lib "CL32.DLL" ( ByVal cryptContext As Long) As LongPublic Declare Function cryptAsyncQuery Lib "CL32.DLL" ( ByVal cryptObject As Long) As LongPublic Declare Function cryptAsyncCancel Lib "CL32.DLL" ( ByVal cryptObject As Long) As Long' Encrypt/decrypt/hash a block of memory ' ***Warning: function 'cryptEncrypt' will replace the String 'buffer'Public Declare Function cryptEncrypt Lib "CL32.DLL" ( ByVal cryptContext As Long, _ ByVal buffer As String, _ ByVal length As Long) As Long' ***Warning: function 'cryptDecrypt' will replace the String 'buffer'Public Declare Function cryptDecrypt Lib "CL32.DLL" ( ByVal cryptContext As Long, _ ByVal buffer As String, _ ByVal length As Long) As Long' Get/set/delete attribute functions Public Declare Function cryptSetAttribute Lib "

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -