2024-11-21

Navigation

Skip Navigation Links

Hash algorithms

Asymmetric Algorithms

Symmetric Cipher Algorithms

Encoding Algorithms

Compression Algorithms

Pseudo Random Number Algorithms

Steganography

Library Wrappers

String Comparison

Others

Syntax highlighting by Prism
PBCrypto.com Mirror

MS CryptoAPI PowerBASIC Source

Algorithm creator(s)

Microsoft


PB author(s)

Don Dickinson


Description

Don has kindly ported the MS CryptoAPI header files to PowerBASIC and created a demo to show you how to use them.


Note

Required files: wincrypt.inc (available as *.bas here due to hosting restrictions), ddwcrypt.bas


Source

n/a


See also


Source Code

Download source code file cryptoapi.bas (Right-click -> "Save as ...")

'  cryptoapi.bas (originally crtest.bas)
'
'  PB-DLL/CC 32-bit MS CryptoAPI wrapper functions
'
'  PBDLL6 test program to demonstrate the use of
'  the ddwcrypt.bas wrapper for the Microsoft RSA
'  Base Provider stream encryption.
'
#Compile Exe
#Include "win32api.inc"
#Include "wincrypt.inc"   '/pbcrypto/algorithms/source/include/wincrypt.inc
#Include "ddwcrypt.bas"   '/pbcrypto/algorithms/source/include/ddwcrypt.bas
 
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub Test_FileToFile

   Dim sFile As String
   Dim outFile As String
   Dim decFile As String

   sFile = "c:\i_view32.exe"

   '- Delete the output files as the function
   '  will fail if they exist.
   '
   outFile = "c:\iview.enc"
   If Dir$(outFile) <> "" Then
      Kill outFile
   End If

   decFile = "c:\testit.exe"
   If Dir$(decFile) <> "" Then
      Kill decFile
   End If

   If creFileToFile(sFile, outFile, "Password") Then
      MsgBox "File Encrypted: " + sFile + "==>" + outFile
      If crdFiletoFile(outFile, decFile, "Password") Then
         MsgBox "File Decrypted: " + outFile + "==>" + decFile
      Else
         MsgBox "Error decrypting file: " + outFile + " to " + decFile
      End If
   Else
      MsgBox "Error encrypting file: " + sFile
   End If

End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub Test_StringToFile

   Dim sFile As String
   Dim sInput As String
   Dim sOutput As String

   '- Delete the output file as the function
   '  will fail if it exists.
   '
   sFile = "c:\test.encrypt"
   If Dir$(sFile) <> "" Then
      Kill sFile
   End If

   sInput = "This is a test"
   If creStringToFile(sInput, sFile, "Password") Then
      MsgBox "String Encrypted to file: " + sInput
      If crdFileToString(sFile, sOutput, "Password") Then
         MsgBox "String Decrypted From File" + sOutput
      Else
         MsgBox "Error decrypting file: " + sFile
      End If
   Else
      MsgBox "Error encrypting file: " + sFile
   End If
End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub Test_StringToString
   Dim sInput As String
   Dim sOutput As String
   sInput = "This is a test"
   If creStringToString(sInput, sOutput, "Password") = %False Then
      MsgBox "Error Encrypting"
   Else
      MsgBox "Encrypted String:" + $cr + sInput + $cr + sOutput
      If crdStringToString(sOutput, sInput, "Password") = %False Then
         MsgBox "Error Decrypting"
      Else
         MsgBox "Decrypted String:" + $cr + sOutput + $cr + sInput
      End If
   End If
End Sub

'
'  PBMain - program entry point
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function PBMain
   Test_FileToFile
   Test_StringToFile
   Test_StringToString
End Function

Mirror provided by Knuth Konrad