IS.HASH.SHA1: Generating with UniBASIC DIGEST command

In cryptography, SHA-1 (Secure Hash Algorithm 1) is a cryptographic hash function designed by the United States National Security Agency and is a U.S. Federal Information Processing Standard published by the United States NIST. SHA1 is used in many places to generate a unique hash value representing a string or file. It is widely used in place of MD4 and MD5 hash as a more secure hash value. While not as secure as SHA256, it is still used in many places for data integrity, version control, and other features that need an unique one-way signatures.

SHA1 Function

SHA-1 produces a 160-bit (20-byte) hash value known as a message digest. A SHA-1 hash value is typically rendered as a hexadecimal number, 40 digits long.

SHA1("The quick brown fox jumps over the lazy dog")

gives hexadecimal:

2fd4e1c67a2d28fced849ee1bb76e7391b93eb12

SHA1 will detect even small changes in the string and cause the returned hash value to change. You can always read more about SHA1 at:

https://en.wikipedia.org/wiki/SHA-1

UniBASIC Hashing

UniBASIC comes with hashing extensions in the form of DIGEST(). The DIGEST has SHA1 built-in. This allows you to use code like the example below.

SHA1.MESSAGE = "The quick brown fox jumps over the lazy dog"
ret = DIGEST('SHA1',SHA1.MESSAGE, 1, SHA1.HASH)
CRT SHA1.HASH : ' = 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12

The subroutine found with this article is based on the code above, but has been structured to be interchangeable with non-UniBASIC versions of the SHA1 subroutine also found on the International Spectrum Website at: http://www.intl-spectrum.com/resource/756/default.aspx.

Example

SHA1.MESSAGE = "The quick brown fox jumps over the lazy dog"
CALL IS.HASH.SHA1(SHA1.MESSAGE,HASH.VALUE)
*
TEST.VALUE = "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"
CRT HASH.VALUE : " =" : TEST.VALUE :" - "
IF (HASH.VALUE EQ TEST.VALUE) THEN
  CRT "Ok"
END ELSE
  CRT "Failed"
END

Output

2fd4e1c67a2d28fced849ee1bb76e7391b93eb12 = 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12 - Ok

Downloads:

Nathan Rector

Nathan Rector, President of International Spectrum, has been in the MultiValue marketplace as a consultant, author, and presenter since 1992. As a consultant, Nathan specialized in integrating MultiValue applications with other devices and non-MultiValue data, structures, and applications into existing MultiValue databases. During that time, Nathan worked with PDA, Mobile Device, Handheld scanners, POS, and other manufacturing and distribution interfaces.

In 2006, Nathan purchased International Spectrum Magazine and Conference and has been working with the MultiValue Community to expand its reach into current technologies and markets. During this time he has been providing mentorship training to people converting Console Applications (Green Screen/Text Driven) to GUI (Graphical User Interfaces), Mobile, and Web. He has also been working with new developers to the MultiValue Marketplace to train them in how MultiValue works and acts, as well as how it differs from the traditional Relational Database Model (SQL).

View more articles

Featured:

IS.HASH.SHA1: Generating SHA1 values with Generic MultiValue BASIC

IS.HASH.HMACSHA1: Generating HMAC-SHA1 Values with Generic MultiValue BASIC

menu
menu