Click here to Skip to main content
12,762,900 members (34,908 online)
Click here to Skip to main content
Add your own
alternative version


15 bookmarked
Posted 12 May 2008

Cryptography application

, 12 May 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
Application for Encription and decription

DecryptoImage - maximum width is 600 pixels CryptoImage width=


This is useful application for keeping data on safely place in your computer.


Is there any background to this article that may be useful such as an introduction to the basic ideas presented?

Today is very popular spying and stealing.With time we understand necessity for keeping our data on special places and under safely encription.This is something about we must thinking..

Using the code

Step 1. What do you need to do :
1. In your WebSite directory add folder zastita
2. In folder zastita put Default.aspx page

Imports Microsoft.VisualBasic
Imports System.Security.Cryptography
Public Class zastita_Default
    Inherits System.Web.UI.Page
    Dim filepart As String

    Sub Crypt()
        Dim textinput As String
        Dim password As String
        password = Lozinka.Text()
        textinput = Ciuso.Text()
        filepart = TextBox1.Text
        Dim empire As New crypto(password)
        Dim cryptoText As String = empire.EncryptData(textinput)

        Ciuso.Text = ("The crypto text is: " &_
        My.Computer.FileSystem.WriteAllText( _
            &filepart, cryptoText, False)
    End Sub
    Sub Decrypt()
        filepart = TextBox1.Text
        Dim cryptoText As String = _
        My.Computer.FileSystem.ReadAllText( _
        My.Computer.FileSystem.SpecialDirectories.MyDocuments _
        & filepart)

        Dim password As String
        password = Lozinka.Text()
        Dim empire As New crypto(password)

            Dim textinput As String = _
            Ciuso.Text = (textinput)
        Catch ex As _
            MsgBox("Please write correct password           ",_                    
            MsgBoxStyle.Information, "Information")

        End Try
    End Sub

    Protected Sub EncodeB_Click(ByVal sender As Object,_
    ByVal e As System.EventArgs) Handles EncodeB.Click
    End Sub

    Protected Sub DecodeB_Click(ByVal sender As Object,_
    ByVal e As System.EventArgs) Handles DecodeB.Click
    End Sub   
End Class

Step 2. In App_Code folder put crypto.vb page


Imports Microsoft.VisualBasic
Imports System.Security.Cryptography

Public NotInheritable Class crypto
    Inherits System.Web.UI.Page
    Private TripleDes As New _
    Private Function TruncateHash( _
    ByVal key As String, _
    ByVal length As Integer) _
    As Byte()
        Dim sha1 As New SHA1CryptoServiceProvider()
        Dim keyBytes() As Byte = _
        Dim hash() As Byte = sha1.ComputeHash(keyBytes)

        ReDim Preserve hash(length - 1)
        Return hash
    End Function
    Sub New(ByVal key As String)
        TripleDes.Key = TruncateHash(key,_
        TripleDes.KeySize \ 8)
        TripleDes.IV = TruncateHash("", _
        TripleDes.BlockSize \ 8)
    End Sub
    Public Function EncryptData( _
        ByVal textinput As String) _
        As String

        Dim textinputBytes() As Byte = _
        Dim ms As New System.IO.MemoryStream
        Dim encStream As New CryptoStream(ms,_
        TripleDes.CreateEncryptor(), _

        encStream.Write(textinputBytes, 0,textinputBytes.Length)

        Return Convert.ToBase64String(ms.ToArray)
    End Function
    Public Function DecryptData(ByVal encryptedtext As_
    String) As String
        Dim encryptedBytes() As Byte = Convert.FromBase64String_
        Dim ms As New System.IO.MemoryStream
        Dim decStream As New CryptoStream_
        (ms,TripleDes.CreateDecryptor(), _

        decStream.Write(encryptedBytes, 0, encryptedBytes.Length)

        Return System.Text.Encoding.Unicode.GetString(ms.ToArray)
    End Function

End Class


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Marijan Ivicevic - Bakulic
Web Developer
Croatia Croatia
Good evening !

I was born 18.10.1969.In Zagreb(Croatia)
My pleasure is in our cooperation.
Like a Photographer,Graphic designer,
Web designer and with smooth finish
in Programming Internet applications
is secret of my good spirit.
Find my interests in Designing and
programming in XML,SQL,VB,Action script,
Like nature,skiing,swimming,fishing,fightsports.

Kinds regards

You may also be interested in...


Comments and Discussions

GeneralMy vote of 1 Pin
Dave Kreskowiak13-Jan-10 8:47
mvpDave Kreskowiak13-Jan-10 8:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 12 May 2008
Article Copyright 2008 by Marijan Ivicevic - Bakulic
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid