Encrypt-Decrypt using Capicom On Visual Basic 6.0

Dear all reader, This time i will share about ecrypt & decrypt using Capicom. Before we start the code section, i will explain what is Capicom. Capicom is an ActiveX control created by Microsoft to help expose a select set of Microsoft Cryptographic Application Programming Interface (CryptoAPI) functions through Microsoft Component Object Model (COM). It was intended to enable every environment that supports ActiveX to use Microsoft Cryptographic technologies, including web pages that are opened with Microsoft Internet Explorer or any other web browser that supports ActiveX.

CAPICOM can be used to digitally sign data, inspect, verify and display their digital signature and/or digital certificate, add or remove certificates to or from the certificate stores, and finally, to encrypt or decrypt data.

CAPICOM Version 2.1.0.2, the latest and last version of CAPICOM, is officially supported on Windows Vista.However, Microsoft has announced that CAPICOM is discontinued and is no longer being developed. Microsoft suggests replacing CAPICOM with .NET Framework’s X509 Cryptographic Classes and a number of other alternatives.

Ok, let start code it. In this tutorial we need Capicom.dll, Usually located on C:\Windows\System32\Capicom.dll. Add Capicon into vb project (Project -> Reference -> Browse and add capicom.dll). After we add capicom to visual basic project, add 3 TextBoxs (name => tbPlain, tbHash, tbSecret, 3 Labels and 2 Command Button (name => btnEnc, btnDecrypt) to form. And copy & paste code below into form

encdeccapicom

Private Sub btnDecrypt_Click()
On Error GoTo errHDL
Dim sPlain As String

If tbHash.Text <> “” And tbSecret.Text <> “” Then
sPlain = DecryptString
If sPlain <> “” Then
tbPlain.Text = sPlain
tbHash.Text = “”
tbSecret.Text = “”
End If
End If
Exit Sub
errHDL:
MsgBox Err.Number & ” – ” & Err.Description
End Sub

Private Sub btnEnc_Click()
On Error GoTo errHDL
Dim sHash As String

If tbPlain.Text <> “” And tbSecret.Text <> “” Then

sHash = EncryptString(Trim(tbPlain.Text))

If sHash <> “” Then
tbHash.Text = sHash
tbPlain.Text = “”
tbSecret.Text = “”
End If

End If
Exit Sub
errHDL:
MsgBox Err.Number & ” – ” & Err.Description
End Sub

Private Function DecryptString() As String
Dim oDecrypt As New EncryptedData
Dim sRet As String
On Error GoTo errHDL
oDecrypt.SetSecret (Trim(tbSecret.Text))
oDecrypt.Decrypt (tbHash.Text)
sRet = oDecrypt.Content
DecryptString = sRet
Exit Function
errHDL:
MsgBox Err.Number & ” – ” & Err.Description
Set oDecrypt = Nothing
End Function

Private Function EncryptString(ByVal sValue As String) As String
Dim oEncrypt As New EncryptedData
Dim sRet As String
On Error GoTo errHDL

oEncrypt.Algorithm = CAPICOM_ENCRYPTION_ALGORITHM_AES
oEncrypt.Algorithm.KeyLength = CAPICOM_ENCRYPTION_KEY_LENGTH_MAXIMUM
oEncrypt.SetSecret (tbSecret)
oEncrypt.Content = sValue
sRet = oEncrypt.Encrypt(CAPICOM_ENCODE_BASE64)
EncryptString = sRet

Exit Function
errHDL:
MsgBox Err.Number & ” – ” & Err.Description
Set oEncrypt = Nothing
End Function

Run this project with pressing F5 on your keyboard.

You can download this project onĀ  http://yadoy666.serverisdown.org/files/encDecCapicom.rar

  • Share/Bookmark

4 Comments

  1. YaDoY666 says:

    Jangan ada PERTAMAX diantara kita. Hahahahahaha ^_^

  2. denbayan says:

    nice tutorial
    ijin unduh ah ,,, :beer:
    btw saya keduax
    xixixixi

  3. LOL1ds says:

    Ketiga…
    Waduuhh.. gawe bahasa jawa bisa apa engga’ ya, heuheuheu.. :D
    Langsung Ke TKP Cak..! Thanks.
    Not: Terus Di apakno iki..???

  4. 5h1nn says:

    hay kmunitas yadoy666
    q shin
    hacker pmula asal borneo
    bleh gabunk n shering tntang hacker g
    ad num contact yg bs d hbgn g??
    bls k e-mail q yaw kwn ^^
    shin_mirwan@yahoo.com
    thx 4 all

Leave a Reply