Jump to content
Fivewin Brasil

Compilar crypt.prg com Harbour


kapiaba

Recommended Posts

Quem usa HARBOUR, poderia compilar este exemplo, e me dizer quais as LIBS que eu tenho que usar para compilar?

/*
 * $Id: crypt.prg 11888 2009-07-23 19:46:11Z vszakats $
 */
	/*
 * Copyright 2009 Viktor Szakats (harbour.01 syenar.hu)
 * www - http://www.harbour-project.org
 */
	#include "FiveWin.ch"
#include "simpleio.ch"
#include "hbssl.ch"
	PROCEDURE Main()
	   LOCAL ctx
   LOCAL result
   LOCAL encrypted
   LOCAL decrypted
	   LOCAL cKey := "key"
	   LOCAL a, iv, pub
   LOCAL bioe
   LOCAL tmp
	   LOCAL all := {;
       @PEM_READ_BIO_PRIVATEKEY()      ,;
       @PEM_READ_BIO_PUBKEY()          ,; //
       @PEM_READ_BIO_RSAPRIVATEKEY()   ,;
       @PEM_READ_BIO_RSAPUBLICKEY()    ,;
       @PEM_READ_BIO_RSA_PUBKEY()      ,; //
       @PEM_READ_BIO_DSAPRIVATEKEY()   ,;
       @PEM_READ_BIO_DSA_PUBKEY()      ,;
       @PEM_READ_BIO_DSAPARAMS()       ,;
       @PEM_READ_BIO_DHPARAMS()        ,;
       @PEM_READ_BIO_X509()            ,;
       @PEM_READ_BIO_X509_AUX()        ,;
       @PEM_READ_BIO_X509_REQ()        ,;
       @PEM_READ_BIO_X509_CRL()        ,;
       @PEM_READ_BIO_PKCS7()           }
	   OpenSSL_add_all_ciphers()
	   ctx := hb_EVP_CIPHER_CTX_create()
   EVP_CIPHER_CTX_init( ctx )
	   EVP_EncryptInit( ctx, "AES-192-OFB", cKey )
   ? EVP_CIPHER_CTX_cipher( ctx )
   ? EVP_CIPHER_block_size( EVP_CIPHER_CTX_cipher( ctx ) )
	   encrypted := ""
   result := ""
   EVP_EncryptUpdate( ctx, @result, "sample text" )
   encrypted += result
   EVP_EncryptFinal( ctx, @result )
   encrypted += result
   ? "ENCRYTPTED", ">" + hb_StrToHex( encrypted ) + "<"
   ? ">" + encrypted + "<"
	   ctx := hb_EVP_CIPHER_CTX_create()
	   EVP_DecryptInit( ctx, "AES-192-OFB", cKey )
	   decrypted := ""
   result := ""
   EVP_DecryptUpdate( ctx, @result, encrypted )
   decrypted += result
   EVP_DecryptFinal( ctx, @result )
   decrypted += result
   ? "DECRYTPTED", ">" + decrypted + "<"
	   ? ERR_load_PEM_strings()
   ? OpenSSL_add_all_algorithms()
	   ctx := hb_EVP_CIPHER_CTX_create()
	   ? "=============="
   bioe := BIO_new_fd( 1, HB_BIO_NOCLOSE )
   FOR EACH tmp IN all
      ? tmp:__enumIndex(), pub := tmp:exec( "pubkey.pem", "test" )
      IF ! Empty( pub )
         ? "EVP_PKEY_free", EVP_PKEY_free( pub )
      ENDIF
      ? ; ERR_print_errors( bioe )
   NEXT
   BIO_free( bioe )
	   ? pub := PEM_READ_BIO_PUBKEY( "pubkey.pem", "test" )
	   ? "EVP_SealInit", EVP_SealInit( ctx, "AES-192-OFB", @a, @iv, { pub } )
   ? ValType( a ), Len( a )
   ? ValType( a[ 1 ] ), ">" + hb_StrToHex( a[ 1 ] ) + "<"
   ? ValType( iv ), ">" + hb_StrToHex( iv ) + "<"
	   ? "EVP_PKEY_free", EVP_PKEY_free( pub )
	   ctx := NIL
	   EVP_cleanup()
	   RETURN


Link to comment
Share on other sites

Amiguinhos,

 

kapiaba

Conseguiu testar? eu peguei o seu exemplo e fiz um teste com meu Harbour 3.2-17626.

No começo "deumapádierro" ai encontrei uma das bibliotecas necessárias que tinham alterações já propostas pelo TheFull, onde as funções internas começavam com underline( _ ).

Depois fiz os passos dele sobre a outra biblioteca e consegui reduzir os erros a um. Me faltou uma chamada a função GetPrivateKey() no exemplo dele e a chamada a um método EXEC no seu exemplo.

https://bitbucket.org/fivetech/harbour-xharbour-builds/downloads/OpenSSL-Win32.zip

https://bitbucket.org/fivetech/harbour-xharbour-builds/downloads/hb_ssl_libs.zip

https://bitbucket.org/fivetech/harbour-xharbour-builds/downloads/harbour_hbssl_bcc7_32_2016Dec.zop

https://bitbucket.org/fivetech/harbour-xharbour-builds/downloads/xharbour_bcc70_20161218.zip

Discussão: http://forums.fivetechsupport.com/viewtopic.php?f=6&t=23539&start=0&hilit=hbssl.lib

Veja se funciona com sua pessoa.

ssleay32.lib

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...