Files
harbour-core/contrib/hbssl/tests/digest.prg
Viktor Szakats 58faf91453 2016-01-14 19:17 UTC+0100 Viktor Szakats (vszakats users.noreply.github.com)
* *
    % remove brandings and homepage [1] from copyright header. Pass 1 - using script.
      [1] nobody has access to it anymore AFAIK - and it's also just
          a redirect since long
    ! update url in copyright header
    ; this should make the diff between 3.4 and 3.2 easier to manage
2016-01-14 19:18:17 +01:00

73 lines
1.7 KiB
Plaintext

/*
* Copyright 2009 Viktor Szakats (vszakats.net/harbour)
*/
#require "hbssl"
PROCEDURE Main()
LOCAL ctx
LOCAL digest
LOCAL key
LOCAL iv
SSL_init()
OpenSSL_add_all_digests()
OpenSSL_add_all_ciphers()
? "Version built against:", hb_NumToHex( OPENSSL_VERSION() )
? "Version loaded:", hb_NumToHex( SSLeay() )
ctx := EVP_MD_CTX_create()
EVP_MD_CTX_init( ctx )
EVP_DigestInit_ex( ctx, "SHA256" )
EVP_DigestUpdate( ctx, "sample text" )
digest := ""
EVP_DigestFinal( ctx, @digest )
? "SHA256", ">" + hb_StrToHex( digest ) + "<"
EVP_DigestInit_ex( ctx, HB_EVP_MD_SHA256 )
EVP_DigestUpdate( ctx, "sample text" )
digest := ""
EVP_DigestFinal( ctx, @digest )
? "SHA256", ">" + hb_StrToHex( digest ) + "<"
EVP_MD_CTX_cleanup( ctx )
EVP_DigestInit_ex( ctx, HB_EVP_MD_RIPEMD160 )
EVP_DigestUpdate( ctx, "sample text" )
digest := ""
EVP_DigestFinal( ctx, @digest )
? "RIPEMD160", ">" + hb_StrToHex( digest ) + "<"
key := ""
iv := ""
? "EVP_BytesToKey", EVP_BytesToKey( HB_EVP_CIPHER_AES_192_OFB, HB_EVP_MD_SHA256, "salt1234", "data", 2, @key, @iv )
? "KEY", hb_StrToHex( key )
? ">" + key + "<"
? "IV", hb_StrToHex( iv )
? ">" + iv + "<"
key := ""
iv := ""
? "EVP_BytesToKey", EVP_BytesToKey( "AES-192-OFB", "SHA256", "salt1234", "data", 2, @key, @iv )
? "KEY", hb_StrToHex( key )
? ">" + key + "<"
? "IV", hb_StrToHex( iv )
? ">" + iv + "<"
key := ""
iv := ""
? "EVP_BytesToKey", EVP_BytesToKey( "AES-192-OFB", "SHA256",, "data", 2, @key, @iv )
? "KEY", hb_StrToHex( key )
? ">" + key + "<"
? "IV", hb_StrToHex( iv )
? ">" + iv + "<"
EVP_cleanup()
RETURN