Encrypt-Decrypt using Capicom On Visual Basic 6.0

Filed in Programming 4 comments

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

Posted by YaDoY666   @   3 December 2009 4 comments
Tags : , , , , ,

Share This Post

RSS Digg Twitter StumbleUpon Delicious Technorati

4 Comments

Comments
Dec 3, 2009
12:51
#1 YaDoY666 :

Jangan ada PERTAMAX diantara kita. Hahahahahaha ^_^

Dec 4, 2009
08:50
#2 denbayan :

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

Dec 5, 2009
14:06
#3 LOL1ds :

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

Jan 28, 2010
08:49
#4 5h1nn :

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 Comment

Previous Post
«
Next Post
»
Black Tribe designed by Premium Wordpress Themes  |  Brought to you by Windows Hosting from the #1 Web Hosting Provider - HostNexus.