Encryption SHA256

Posted on 2006-05-05
Last Modified: 2010-04-23
Hi Everyone,

        I need to encrypt the password entered by the user. Does anyone know the code for SHA256?? please keep it as simple as possible. What i was able to find on the internet is this:

    Protected Shared Function SHA256_Encrypt(ByVal Txt As String) As String

        Dim sha As New SHA256Managed()
        Dim ae As New ASCIIEncoding()
        Dim Hash() As Byte = sha.ComputeHash(ae.GetBytes(Txt))
        Dim sb As New StringBuilder(Hash.Length * 2)
        Dim ndx As Integer

        For ndx = 0 To Hash.Length - 1
            sb.Append(Right("0" & Hex(Hash(ndx)), 2)) <----- the word right not being accepted

        Return sb.ToString

    End Function

Now for some reason the word right is not being accepted and when i go over the word it tells me: "Cannot refer to an instance member of a class from within a shared method or shared method initilizer without an explict instance of the class"

this was taken from:

Any ideas???

Question by:aborg85
    LVL 9

    Accepted Solution


    Your problem has nothing to do with encryption. It is a visual basic legacy problem.

    Right is used by the property Forms.Right in the namespace System.Forms and is therefore called by default.

    Use following namespace: Microsoft.Visualbasic.Right

    sb.Append(Microsoft.VisualBasic.Right("0" & Hex(Hash(ndx)), 2)) ' <----- the word right not being accepted

    The rest orf your function is working fine.

    Author Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now