Alaska Software Inc. - sha
Username: Password:
AuthorTopic: sha
Osvaldo Ramirezsha
on Tue, 16 Feb 2021 15:34:35 -0700
Hello guys

Does Xbase++ has a sha2/md5/sha functions ?

Best Regards
Osvaldo Ramirez
Ricardo CayssialsRe: sha
on Sat, 20 Feb 2021 16:07:37 +0100
Osvaldo Ramirez wrote in message news:c12fe50$50e9f776$53dd0@news.alaska-
software.com...
>Hello guys
>
>Does Xbase++ has a sha2/md5/sha functions ?
>
>Best Regards
>Osvaldo Ramirez

Hello.
I use Char2Hash() in Alaska or Str2Md5Hex() from ot4xb.lib.
Best regards.
Ricardo
Osvaldo RamirezRe: sha
on Sat, 20 Feb 2021 08:39:31 -0700
On 20/02/21 8:07, Ricardo Cayssials wrote:
> Osvaldo Ramirez wrote in message news:c12fe50$50e9f776$53dd0@news.alaska-
> software.com...
>> Hello guys
>>
>> Does Xbase++ has a sha2/md5/sha functions ?
>>
>> Best Regards
>> Osvaldo Ramirez
> 
> Hello.
> I use Char2Hash() in Alaska or Str2Md5Hex() from ot4xb.lib.
> Best regards.
> Ricardo
> 
Gracias Ricardo

Best Regards
Osvaldo Ramirez
Boris BorzicRe: sha
on Sat, 20 Feb 2021 19:10:07 +0100
Ricardo Cayssials wrote in news:3d72bed3$769db912$7e248@news.alaska-
software.com:

>>Does Xbase++ has a sha2/md5/sha functions ?
>>
>>Best Regards
>>Osvaldo Ramirez
> 
> I use Char2Hash() in Alaska or Str2Md5Hex() from ot4xb.lib.


Also xbHash() from Xb2.NET library. 

Supports following hash algorithms:
MD4, MD5, RIPEMD160, SHA1, SHA224, SHA256, SHA384, SHA512, WHIRLPOOL, MDC2,
SHA3_224, SHA3_256, SHA3_384, SHA3_512

Best regards,
Boris Borzic

http://xb2.net
http://sqlexpress.net
industrial strength Xbase++ development tools
Steven SchefferRe: sha
on Tue, 20 Jul 2021 09:33:40 +0200
You can use OpenSSL it free and easy to use.

Regards,
Steven

#include "dll.ch"
#include "common.ch"

FUNCTION MAIN()
  LOCAL aSHA1Test := { { "The quick brown fox jumps over the lazy dog", "2fd4e1c6 7a2d28fc ed849ee1 bb76e739 1b93eb12" },;
                       { "The quick brown fox jumps over the lazy cog", "de9f2c7f d25e1b3a fad3e85a 0bd17d9b 100db4b3" },;
                       { "", "da39a3ee 5e6b4b0d 3255bfef 95601890 afd80709" } }
  LOCAL nSHA1Pos
  LOCAL cMemo := ""
  LOCAL mdctx := NIL
  LOCAL md := NIL
  LOCAL cHash := NIL
  LOCAL nlengthOfHash := 0
  LOCAL cSHA1 := ""

#define EVP_MAX_MD_SIZE 64     /* SHA512 */

  cMemo := "SHA1 test"+CHR(13)+CHR(10)
  FOR nSHA1Pos := 1 TO LEN( aSHA1Test )
    mdctx := EVP_MD_CTX_new()
    ? mdctx
    md := EVP_sha1()
    EVP_DigestInit_ex( mdctx, md, NIL )
    ? aSHA1Test[nSHA1Pos,1]
    EVP_DigestUpdate( mdctx, aSHA1Test[nSHA1Pos,1], LEN( aSHA1Test[nSHA1Pos,1] ) )

    cHash := REPLICATE(CHR(0), EVP_MAX_MD_SIZE)
    nlengthOfHash := 0
    EVP_DigestFinal_ex( mdctx, @cHash, @nLengthOfHash )
    cHash := LEFT( cHash, nLengthOfHash )

    cSHA1 := str2SHA1( cHash )
    cMemo += "("+LTRIM(STR(nSHA1Pos))+") input:"+aSHA1Test[nSHA1Pos,1]+CHR(13)+CHR(10)+;
             aSHA1Test[nSHA1Pos,2]+" hash output"+CHR(13)+CHR(10)+;
             cSHA1+" hash openSSL call"+CHR(13)+CHR(10)+;
             "equal:"+IIF( cSHA1=aSHA1Test[nSHA1Pos,2], ".T.", ".F." )+CHR(13)+CHR(10)+CHR(13)+CHR(10)

    EVP_MD_CTX_free( mdctx )
  NEXT
  ftMemoWrit( "Result.SHA1", cMemo )
  RETURN NIL



 Allocates and returns a digest context.
DLLFUNCTION EVP_MD_CTX_new() USING STDCALL FROM libcrypto-1_1.dll
 Cleans up digest context ctx and frees up the space allocated to it.
DLLFUNCTION EVP_MD_CTX_free( mdctx ) USING STDCALL FROM libcrypto-1_1.dll

 Sets up digest context ctx to use a digest type from ENGINE impl. type will
 typically be supplied by a function such as EVP_sha1(). If impl is NULL then
 the default implementation of digest type is used.
DLLFUNCTION EVP_DigestInit_ex( mdctx, md, x ) USING STDCALL FROM libcrypto-1_1.dll

DLLFUNCTION EVP_sha256() USING STDCALL FROM libcrypto-1_1.dll
DLLFUNCTION EVP_sha1() USING STDCALL FROM libcrypto-1_1.dll

DLLFUNCTION EVP_DigestUpdate( mdctx, cStr, nLength ) USING STDCALL FROM libcrypto-1_1.dll

DLLFUNCTION EVP_DigestFinal_ex( mdctx, @cHash, @nLengthOfHash ) USING STDCALL FROM libcrypto-1_1.dll




FUNCTION str2SHA1( cHASH )
  LOCAL cSha1 := ""
  LOCAL cRetVal := "", nI := 1

  cSha1 := LOWER(StrToHex(cHASH))
  DO WHILE nI < LEN( cSha1 )
    cRetVal += SUBSTR(cSha1,nI,8)+" "
    nI += 8
  ENDDO
  cRetVal := RTRIM(cRetVal)
  RETURN ( cRetVal )
Osvaldo RamirezRe: sha
on Tue, 20 Jul 2021 08:35:32 -0600
On 20/07/21 1:33, Steven Scheffer wrote:
> You can use OpenSSL it free and easy to use.
> 
> Regards,
> Steven
> 
> #include "dll.ch"
> #include "common.ch"
> 
> FUNCTION MAIN()
>    LOCAL aSHA1Test := { { "The quick brown fox jumps over the lazy dog", "2fd4e1c6 7a2d28fc ed849ee1 bb76e739 1b93eb12" },;
>                         { "The quick brown fox jumps over the lazy cog", "de9f2c7f d25e1b3a fad3e85a 0bd17d9b 100db4b3" },;
>                         { "", "da39a3ee 5e6b4b0d 3255bfef 95601890 afd80709" } }
>    LOCAL nSHA1Pos
>    LOCAL cMemo := ""
>    LOCAL mdctx := NIL
>    LOCAL md := NIL
>    LOCAL cHash := NIL
>    LOCAL nlengthOfHash := 0
>    LOCAL cSHA1 := ""
> 
> #define EVP_MAX_MD_SIZE 64     /* SHA512 */
> 
>    cMemo := "SHA1 test"+CHR(13)+CHR(10)
>    FOR nSHA1Pos := 1 TO LEN( aSHA1Test )
>      mdctx := EVP_MD_CTX_new()
>      ? mdctx
>      md := EVP_sha1()
>      EVP_DigestInit_ex( mdctx, md, NIL )
>      ? aSHA1Test[nSHA1Pos,1]
>      EVP_DigestUpdate( mdctx, aSHA1Test[nSHA1Pos,1], LEN( aSHA1Test[nSHA1Pos,1] ) )
> 
>      cHash := REPLICATE(CHR(0), EVP_MAX_MD_SIZE)
>      nlengthOfHash := 0
>      EVP_DigestFinal_ex( mdctx, @cHash, @nLengthOfHash )
>      cHash := LEFT( cHash, nLengthOfHash )
> 
>      cSHA1 := str2SHA1( cHash )
>      cMemo += "("+LTRIM(STR(nSHA1Pos))+") input:"+aSHA1Test[nSHA1Pos,1]+CHR(13)+CHR(10)+;
>               aSHA1Test[nSHA1Pos,2]+" hash output"+CHR(13)+CHR(10)+;
>               cSHA1+" hash openSSL call"+CHR(13)+CHR(10)+;
>               "equal:"+IIF( cSHA1=aSHA1Test[nSHA1Pos,2], ".T.", ".F." )+CHR(13)+CHR(10)+CHR(13)+CHR(10)
> 
>      EVP_MD_CTX_free( mdctx )
>    NEXT
>    ftMemoWrit( "Result.SHA1", cMemo )
>    RETURN NIL
> 
> 
> 
>  Allocates and returns a digest context.
> DLLFUNCTION EVP_MD_CTX_new() USING STDCALL FROM libcrypto-1_1.dll
>  Cleans up digest context ctx and frees up the space allocated to it.
> DLLFUNCTION EVP_MD_CTX_free( mdctx ) USING STDCALL FROM libcrypto-1_1.dll
> 
>  Sets up digest context ctx to use a digest type from ENGINE impl. type will
>  typically be supplied by a function such as EVP_sha1(). If impl is NULL then
>  the default implementation of digest type is used.
> DLLFUNCTION EVP_DigestInit_ex( mdctx, md, x ) USING STDCALL FROM libcrypto-1_1.dll
> 
> DLLFUNCTION EVP_sha256() USING STDCALL FROM libcrypto-1_1.dll
> DLLFUNCTION EVP_sha1() USING STDCALL FROM libcrypto-1_1.dll
> 
> DLLFUNCTION EVP_DigestUpdate( mdctx, cStr, nLength ) USING STDCALL FROM libcrypto-1_1.dll
> 
> DLLFUNCTION EVP_DigestFinal_ex( mdctx, @cHash, @nLengthOfHash ) USING STDCALL FROM libcrypto-1_1.dll
> 
> 
> 
> 
> FUNCTION str2SHA1( cHASH )
>    LOCAL cSha1 := ""
>    LOCAL cRetVal := "", nI := 1
> 
>    cSha1 := LOWER(StrToHex(cHASH))
>    DO WHILE nI < LEN( cSha1 )
>      cRetVal += SUBSTR(cSha1,nI,8)+" "
>      nI += 8
>    ENDDO
>    cRetVal := RTRIM(cRetVal)
>    RETURN ( cRetVal )
> 
Thanks a lot, I will test it.

Best Regards
Osvaldo Ramirez
Osvaldo RamirezRe: sha
on Tue, 20 Jul 2021 11:24:59 -0600
Talking about SSL ...

Question: Can I use certificates as a means of licensing my software?

For example: point of sale has a certificate and when it runs, it must 
first connect to the server to validate if its certificate is active and 
if it is not active, it does not run.

But maybe this is more complex than just asking for a key


Best Regards
Osvaldo Ramirez