Après windows pour les nuls, voici PB pour les bons (ou presque).

Le forum (ô combien francophone) des utilisateurs de Powerbuilder.

Recherche rapide

Annonce

Certaines rubriques, dont des cours, sont uniquement visibles par les membres du forum ^^.
Dans la rubrique Liens & Références, vous avez accès à un sommaire de téléchargement, profitez-en !
Il existe maintenant un nouveau TOPIC "Votre CV en Ligne" accessible uniquement par demande.

#1 24-09-2013 09:34:09

moonella  
Membre
Date d'inscription: 12-06-2013
Messages: 11
Pépites: 75
Banque: 0

[RESOLU] Comment Crypter dans PB

Bonjour,

l'idée est
- d'avoir le mot de passe (mdp sql server) crypté dans le fichier .ini
- d'avoir dans le code Powerbuilder la clé de cryptage / décryptage
et d'utiliser ce package pour lire la clé cryptée dans le .ini, et la decrypter avant de la balancer à SQL server

j'ai fait une recherche sur le net:
http://www.topwizprogramming.com/freecode_crypto.html
Peut etre que le truc ce n'est pas terrible, mais pas mal de liens internet pointent sur cette PBL

pouvez vous me dire comment faire?
Merci

Dernière modification par moonella (24-09-2013 17:59:21)

Hors ligne

 

#2 24-09-2013 09:47:44

erasorz  
Admin
Lieu: Babylone
Date d'inscription: 23-11-2006
Messages: 5121
Pépites: 97,197
Banque: 2,147,483,647

Re: [RESOLU] Comment Crypter dans PB

Bonjour,
Oui c'est une possibilité.
il y a aussi http://www.rgagnon.com/pbdetails/pb-0170.html


N'envoyez jamais un humain faire le travail d'un programme.

Hors ligne

 

#3 24-09-2013 11:20:33

Geo  
Membre completement Geek
Lieu: Binche
Date d'inscription: 15-12-2008
Messages: 119
Pépites: 378
Banque: 0

Re: [RESOLU] Comment Crypter dans PB

Bonjour,

chez nous on est passé par une DLL maison écrite en C pour effectuer ça.
Maintenant, ce qu'il y a dans cette DLL, peu de développeurs le savent


Rien ne sert de courir, il faut partir à point .

Hors ligne

 

#4 24-09-2013 11:30:44

moonella  
Membre
Date d'inscription: 12-06-2013
Messages: 11
Pépites: 75
Banque: 0

Re: [RESOLU] Comment Crypter dans PB

merci comme je suis nouvelle est ce que tu pourrai m aider un peut plus la dessus
j'ai ajouté le pbt crypto8.
et j'essaye d'utliser ses objets/fonctions
n_cryptoapi lnv_crypt
string ls_encrypted

lnv_crypt = CREATE n_cryptoapi
ls_encrypted = lnv_crypt.of_Encrypt(ls_logpass , "SecretKey")
DESTROY lnv_crypt
==> erreur de compilation
comment est ce je peut declarer un objet qui ne fait pas parti de ma solution

Hors ligne

 

#5 24-09-2013 15:37:10

Dadone  
Membre Power Geek
Lieu: Avon (Seine et Marne)
Date d'inscription: 19-02-2007
Messages: 252
Pépites: 985
Banque: 0
Site web

Re: [RESOLU] Comment Crypter dans PB

Tu trouveras ci-dessous le code complet d'un composant de cryptage.
Très simple à utiliser.
Attention le composant hérite d'une classe nvo qui ne contient rien.
Le composant est auto_instancié

Code: pb

forward
global type nvo_fcrypttools from nvo
end type
end forward

global type nvo_fcrypttools from nvo autoinstantiate
end type

type prototypes
PROTECTED:

Function boolean                        &
lext_CryptStringToBinary (  string    pszString    ,  &
                  ulong    cchString    ,  &
                  ulong     dwFlags    ,  &
                Ref blob    pbBinary    ,  &
                Ref ulong  pcbBinary  ,  &
                Ref ulong  pdwSkip    ,  &
                Ref ulong  pdwFlags    &
) Library "SP2AddOn.dll" Alias For "CryptStringToBinaryW"
      
      
Function boolean                        &
lext_CryptBinaryToString  (   Blob pbBinary    ,     &
                  ulong cbBinary    ,     &
                  ulong dwFlags    ,     &
                Ref string pszString  ,     &
                Ref ulong pcchString      &
) Library "SP2AddOn.dll" Alias For "CryptBinaryToStringW"


end prototypes

type variables
PROTECTED:

Protected string is_nvo_fcryptTools = 

Constant String i#_CryptKey = "$#@%&#%@&*"

Constant Long i#_CriptStringBase64 = 1

Long il_keyCode =1

end variables

forward prototypes
public function string of_encoding (string as_stringtoencode, ref string as_returnmessage)
protected function string of_encoding (blob ablob_data, ref string as_returnmessage)
protected function blob of_decoding (string as_encoded)
public function string of_decoding (string as_encoded, ref string as_returnmessage)
public function string of_encrypt (string as_chaine)
public function integer of_decrypt (string as_stringcrypte, ref string as_stringdecrypte)
end prototypes

public function string of_encoding (string as_stringtoencode, ref string as_returnmessage);//--------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------
//----------------------------------
//---------------------------------
//--------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------------------

Long  li_indice
String ls_returnMessage
String ls_null
Blob lblob_dataToEncode
String ls_stringEncoded

SetNull(ls_null)

lblob_dataToEncode = blob(as_stringtoencode)

TRY

For li_indice = 1 to il_keyCode
  ls_stringEncoded = of_encoding(lblob_dataToEncode,ls_returnMessage)
  lblob_dataToEncode = blob(ls_stringEncoded)
  If ls_returnMessage <> "OK" then
    return ls_null
  End if
Next

Return ls_stringEncoded

CATCH (runtimeerror er)
  as_returnMessage = "Erreur dans la fonction of_encoding() de la classe  " + this.className() + " (" + er.GetMessage() + ")"
  return ls_null
End Try



end function

protected function string of_encoding (blob ablob_data, ref string as_returnmessage);//----------------------------------------------------------------------------------------------------------------------
//-------------------------------
//------------------------------
//-----------------------------
//                              
//----------------------------
//---------------------------
//--------------------------------------------------------------------------------------------------------------------

String ls_null                String ls_encoded              ULong lul_len, lul_buflen          Boolean lb_rtn                
as_returnmessage = "OK"

SetNull(ls_null)

lul_len = Len(ablob_data)

lul_buflen = lul_len * 2

If lul_len <= 2 then
  as_returnMessage = 
  return ls_null
End if


ls_encoded = Space(lul_buflen)

lb_rtn = lext_CryptBinaryToString(ablob_data        ,  &
                      lul_len          ,  & 
                      i#_CriptStringBase64  ,  &
                      ls_encoded        ,   &
                      lul_buflen)

If Not lb_rtn Then 
  as_returnMessage =   
  return ls_null
End if

Return ls_encoded

end function

protected function blob of_decoding (string as_encoded);//---------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------
//------------------------------
//-----------------------------
//----------------------------
//--------------------------------------------------------------------------------------------------------------------------------------

Blob lblob_data            //  permet de transformer une chaine en blob
Long ll_lenString          ULong lul_buflen          ULong lul_skip            ULong  lul_pflags          Boolean lb_rtn            
ll_lenString = Len(as_encoded)

lul_buflen = ll_lenString

lblob_data = Blob(Space(ll_lenString))

lb_rtn = lext_CryptStringToBinary(  as_encoded          ,  &
                      ll_lenString          ,  &
                      i#_CriptStringBase64    ,  &
                      lblob_data          ,  &
                      lul_buflen          ,  &
                      lul_skip            ,  &
                      lul_pflags)

Return BlobMid(lblob_data, 1, lul_buflen)

end function

public function string of_decoding (string as_encoded, ref string as_returnmessage);//--------------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------
//----------------------------------
//---------------------------------
//--------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------

Long  li_indice
String ls_stringDecode
String ls_null

SetNull(ls_null)

ls_stringDecode = as_encoded

TRY

For li_indice = 1 to il_keyCode
  ls_stringDecode = String(of_decoding(ls_stringDecode))
Next

Return ls_stringDecode

CATCH (runtimeerror er)
  as_returnMessage = "Erreur dans la fonction of_decoding() de la classe  " + this.className() + " (" + er.GetMessage() + ")"
  return ls_null
End Try


end function

public function string of_encrypt (string as_chaine);//-------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------
//------------------------------
//-----------------------------
//----------------------------
//----------------------------
//          la chaine avec le code suivant :
//            lblob = blob(ls_chaineCrypte)
//            ls_chaineCrypte = string(blobMid(lblob,1,len(string(lblob))))
//---------------------------------------------------------------------------------------------------------------------------------------

Integer li_indice
Integer li_lenChaine          String ls_chaineCrypte = ""      Blob lblob

li_lenChaine = len(as_chaine)

For li_indice = 1 to li_lenChaine
  ls_chaineCrypte += mid(i#_CryptKey , mod(li_indice,10) + 1, 1)
    ls_chaineCrypte += String(Char(255 - Asc(Mid(as_chaine, li_indice, 1))))
Next

Return ls_chaineCrypte


end function

public function integer of_decrypt (string as_stringcrypte, ref string as_stringdecrypte);//---------------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------
//------------------------------
//                      chaine vide sinon
//-----------------------------
//----------------------------
//-----------------------------
//------------------------------------------------------------------------------------------------------------------------------------------------

Integer  li_indice
Integer  li_lenChaineCrypte        String    ls_stringExtract          // chaine d'extraction 
String ls_mid                

li_lenChaineCrypte = len(as_stringCrypte)

IF not Mod(li_lenChaineCrypte, 2) = 1 then
   as_stringDecrypte = ""

   For li_indice = 2 to (li_lenChaineCrypte + 1) step 2
    ls_stringExtract  = Mid(as_stringCrypte, li_indice - 1, 1)
    ls_mid      = mid(i#_CryptKey, Mod(li_indice / 2, 10) + 1, 1)
    If ls_mid <> ls_stringExtract then
      Return -1
    End if     
        ls_stringExtract      = Mid(as_stringCrypte, li_indice, 1)
        as_stringDecrypte  += string(char(255 - asc(ls_stringExtract)))
  Next
End if


Return 1

end function

on nvo_fcrypttools.create
call super::create
end on

on nvo_fcrypttools.destroy
call super::destroy
end on

Dernière modification par Dadone (24-09-2013 15:49:15)

Hors ligne

 

#6 24-09-2013 16:19:05

seki  
0x73656B69
Award: bf
Lieu: Laquenexy & Luxembourg
Date d'inscription: 20-11-2008
Messages: 1120
Pépites: 4,296,080,217
Banque: 9,223,372,036,854,775,808
Site web

Re: [RESOLU] Comment Crypter dans PB

Dadone a écrit:

Tu trouveras ci-dessous le code complet d'un composant de cryptage.

Et la dll "sp2addon.dll" qui est utilisée par le code ?


The best programs are the ones written when the programmer is supposed to be working on something else. - Melinda Varian

Mes réponses PB sur StackOverflow
http://stackoverflow.com/users/flair/317266.png

Hors ligne

 

#7 24-09-2013 16:32:58

Dadone  
Membre Power Geek
Lieu: Avon (Seine et Marne)
Date d'inscription: 19-02-2007
Messages: 252
Pépites: 985
Banque: 0
Site web

Re: [RESOLU] Comment Crypter dans PB

seki a écrit:

Dadone a écrit:

Tu trouveras ci-dessous le code complet d'un composant de cryptage.

Et la dll "sp2addon.dll" qui est utilisée par le code ?

Tu as raison les dll CryptStringToBinaryW et CryptBinaryToStringW font partie du Microsoft Developer Network (MSDN)

Si quelqu'un est intéressé je peux les lui fournir où y a t'il un moyen de les déposer sur le site ?
Sinon, elles sont récupérables sur le WEB.

Dernière modification par Dadone (24-09-2013 16:38:03)

Hors ligne

 

#8 24-09-2013 17:58:37

moonella  
Membre
Date d'inscription: 12-06-2013
Messages: 11
Pépites: 75
Banque: 0

Re: [RESOLU] Comment Crypter dans PB

merci

Hors ligne

 

Pied de page des forums

Propulsé par FluxBB 1.2.22