If you have Vista then you don't need CAPICOM because you already have a Crypto API streets ahead of XP and so on.
For the following code to work you will need to download Platform SDK Redistributable: CAPICOM.
The library at "C:\Program Files\Microsoft CAPICOM 2.1.0.2 SDK\Lib\X86\capicom.dll' needs to be copied to "C:\WINDOWS\system32\capicom.dll" and registered with 'regsvr32.exe C:\WINDOWS\system32\capicom.dll'.
I've only had CAPICOM a few days and only looked at hashing algorithms and encryption so far.
I was pulling my hair out for a while before I realised that hash values are output in Unicode.
For the following code to work you will need to download Platform SDK Redistributable: CAPICOM.
The library at "C:\Program Files\Microsoft CAPICOM 2.1.0.2 SDK\Lib\X86\capicom.dll' needs to be copied to "C:\WINDOWS\system32\capicom.dll" and registered with 'regsvr32.exe C:\WINDOWS\system32\capicom.dll'.
I've only had CAPICOM a few days and only looked at hashing algorithms and encryption so far.
I was pulling my hair out for a while before I realised that hash values are output in Unicode.

Code:
#Compile Exe #Register None #DIM ALL #TOOLS OFF %NOMMIDS = 1 %NOGDI = 1 %CAPICOM_HASH_ALGORITHM_MD5 = 3 %CAPICOM_HASH_ALGORITHM_SHA256 = 4 %CAPICOM_HASH_ALGORITHM_SHA384 = 5 %CAPICOM_HASH_ALGORITHM_SHA512 = 6 %CAPICOM_ENCRYPTION_ALGORITHM_AES = 4 %CAPICOM_ENCRYPTION_KEY_LENGTH_128_BITS = 3 %CAPICOM_ENCRYPTION_KEY_LENGTH_192_BITS = 4 %CAPICOM_ENCRYPTION_KEY_LENGTH_256_BITS = 5 Function PBMain( ) As Long ' HASHING Local HashedData As IDispatch Local Algorithm As Long Local strMessage, strHashValue As String Let HashedData = NewCOM "CAPICOM.HashedData" strMessage = "PowerBASIC: We put the POWER in BASIC!" ' MD5 Algorithm = %CAPICOM_HASH_ALGORITHM_MD5 Object Let HashedData.Algorithm = Algorithm Object Call HashedData.Hash(strMessage) Object Get HashedData.Value To strHashValue strHashValue = ACode$(strHashValue) MsgBox "MD5: " + strHashValue ' MD5: 2599E6ABE68987C013A1FC084A158060 ' SHA256 Algorithm = %CAPICOM_HASH_ALGORITHM_SHA256 Object Let HashedData.Algorithm = Algorithm Object Call HashedData.Hash(strMessage) Object Get HashedData.Value To strHashValue strHashValue = ACode$(strHashValue) MsgBox "SHA256: " + strHashValue ' SHA256: 7694B1DE8895CD6B3341C0951FCC64A1AFB7CCE97893302EF3319A4098450A15 HashedData = Nothing ' ENCRYPTION Local EncryptedData As IDispatch Local KeyLength As Long Local strPassword, strCipherText, strPlainText As String Let EncryptedData = NewCOM "CAPICOM.EncryptedData" Algorithm = %CAPICOM_ENCRYPTION_ALGORITHM_AES KeyLength = %CAPICOM_ENCRYPTION_KEY_LENGTH_256_BITS strPassword = "2B50831453639A120D5883AAD155ACAE" ' 256 bits worth - it is the only way <smile> ' Encrypt Object Let EncryptedData.Algorithm.Name = Algorithm Object Let EncryptedData.Algorithm.KeyLength = KeyLength Object Let EncryptedData.SetSecret = strPassword Object Let EncryptedData.Content = strMessage Object Call EncryptedData.Encrypt(strCipherText) ' Decrypt ' strMessage = "" Object Let EncryptedData.Content = strMessage Object Call EncryptedData.Decrypt(strCipherText) Object Get EncryptedData.Content To strPlainText MsgBox strPlainText EncryptedData = Nothing End Function
Comment