Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Enumerating data formats currently available on the clipboard
Custom GDI+ class
Mapping and disconnecting network drives
Winsock: sending email messages (SMTP, port 25)
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Winsock: retrieving directory listing from an FTP server using passive data connection (FTP, port 21)
Converting Unicode data from the Clipboard to a character string using a given code page
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
Disk in drive A:
How to display the Properties dialog box for a file (ShellExecuteEx)
Enumerating network resources
Detecting changes in connections to removable drives (VFP9)
Using EnumPrinters function to enumerate locally installed printers
How to download a file from the FTP server using FtpGetFile
Using Font and Text functions
Splash Screen for the VFP application
Using Video Capture: displaying on FoxPro form frames and previewing video obtained from a digital camera
How to play AVI file on the _screen
Retrieving the name of the network resource associated with a local device
Vertical Label control
Subclassing CommandButton control to create BackColor property
Running MSDOS Shell as a child process with redirected input and output (smarter RUN command)
Creating a console window for Visual FoxPro application
How to create MD-5 and SHA-1 hash values from a string

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Versions:
click to open
Before you begin:
Test the presented class as follows:
obj = CREATEOBJECT("TheHash")

? obj.CreateSHA1("test string")

* returns 661295C9CBF9D6B2F6428414504A8DEED3020641

? obj.CreateMD5("test string")
* returns 6F8DB599DE986FAB7A21625B7916589C

See also:
  • Simple class that encrypts and decrypts files using Cryptography API Functions
  • CryptoAPI: Collection of Providers class
  • WinINet function CreateMD5SSOHash
  •  
    using System;
    using System.Text;
    using System.Security.Cryptography;
     
    namespace HashAlgorithms
    {
        class Program
        {
            static void Main()
            {
                ComputeHashDemo();
     
                Console.Write("\n\nAny key...");
                Console.ReadKey();
            }
     
            static void ComputeHashDemo()
            {
                string source = "test string";
                ASCIIEncoding enc = new ASCIIEncoding();
     
                SHA1 sha = new SHA1CryptoServiceProvider();
                MD5 md5 = new MD5CryptoServiceProvider();
     
                byte[] shaHash = sha.ComputeHash(
                    enc.GetBytes(source));
     
                byte[] md5Hash = md5.ComputeHash(
                    enc.GetBytes(source));
     
                Console.WriteLine("{0}\t{1}\t{2}", "SHA1", 
                    shaHash.Length, shaHash.ToHex());
     
                Console.WriteLine("{0}\t{1}\t{2}", "MD5",
                    md5Hash.Length, md5Hash.ToHex());
     
            }
        }
     
        static class ByteExtension
        {
            public static string ToHex(this byte[] me)
            {
                string result = "0x";
                for (int i = 0; i < me.Length; i++)
                {
                    result += me[i].ToString("X2");
                }
                return result;
            }
        }
    }
     

    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    1285 bytes  
    Created: 2005-03-07 15:21:11  
    Modified: 2011-12-10 09:20:22  
    Visits in 7 days: 138  
    Listed functions:
    CryptAcquireContext
    CryptCreateHash
    CryptDestroyHash
    CryptGetHashParam
    CryptHashData
    CryptReleaseContext
    GetLastError
    Printer friendly API declarations
    My comment:
    Transact-SQL HASHBYTES() function computes MD5 and SHA1 hashes identical to those produced by VFP and C# code samples above.



    * * *
    One-way hash functions can be used for creating a fingerprint for a block of data.

    Also hash functions can be used to evaluate passwords. In Users table of your FoxPro application you store not passwords but their hash values.

    It is extremely difficult, if ever possible, to find the original string for a given hash value -- depends on the hash algorithm as well as computer power and methodology you have.

    * * *
    Message Digest: The representation of text in the form of a single string of digits, created using a formula called a one-way hash function.

    One-Way Hash Function: An algorithm that turns messages or text into a fixed string of digits, usually for security or data management purposes. The "one way" means that it is nearly impossible to derive the original text from the string.

    Hash Collision: More than one input message producing identical hash output.

    * * *
    Secure Hash Algorithm, a hash function developed by the NSA for use with NIST Digital Signature Standard (DSS). NSA almost immediately developed a minor change known as SHA-1. Both SHA and SHA-1 produce a 160-bit digest. SHA-1 is used in SSL.

    * * *
    MD-5 is a one-way message-digest hash function. The algorithm processes input text and creates a 128-bit message digest which is unique to the message and can be used to verify data integrity.

    MD-5 was developed by Ron Rivest and is intended to be used in digital signatures applications. Earlier message digest algorithms include obsolete MD-2 and MD-4.

    See also:
  • RFC 1321 - The MD5 Message-Digest Algorithm
  • What are MD2, MD4, and MD5?
  • Example C Program: Creating an MD-5 Hash From File Content.
  • MD5 Online Cracking using Rainbow Tables
  • RFC 3174 - US Secure Hash Algorithm 1 (SHA1)
  • More on Newly Broken SHA1 on Alex Feldstein"s blog
  • Hash Collisions Q&A
  • Word Index links for this example:
    Translate this page:
      Spanish    Portuguese    German    French    Italian  
    FreeTranslation.com offers instant, free translations of text or web pages.
    User Contributed Notes:
    Malcolm Greene | 2005-04-06 00:16:27
    Are there any Windows version (or service pack) dependencies with this code (advapi32.dll)? I've been burned trying to get the FFC _Crypto class to work across different versions of Windows, re: different flavors of rsaenh.dll. (I noticed that rsaenh.dll is not referenced in above code, but I'm still concerned about the same problem version dependencies).

    Thoughts?
    Malcolm

    Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

    Privacy policy
    Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (50.17.109.248)
    4 sec.Function: 'CloseEnhMetaFile'
    Function group: 'Metafile'
    4.61 hrs.Example: 'How to block the ALT+TAB shortcut (WinXP)'
     Example: 'Using Video Capture: displaying on FoxPro form frames and previewing video obtained from a digital camera'
    4.95 hrs.All Functions
     Example: 'Browsing Windows Known Folders (Special Folders)'
     Function: 'GdipSetTextRenderingHint'
    Function group: 'GDI+ Graphics'
    6.65 hrs.Function: 'LoadLibrary'
    Function group: 'Dynamic-Link Library'
    7.92 hrs.Example: 'Converting command-line string to a set of Unicode argument strings (WinNT only)'
     Example: 'Converting image file to .ICO file'
     Solution: 'ContextMenu ActiveX Control'
    Google
    Advertise here!