[Gambas-user] Usage of openssl.EncryptSalted

Benoit Minisini benoit.minisini at gambas-basic.org
Wed May 31 12:36:18 CEST 2023


Le 31/05/2023 à 12:27, Marco Ancillotti a écrit :
> 
> I'm trying to use cipher["DES3"].Encrypt in the place of EncryptSalted ( 
> it seem to be the right call as it take key and iv ) but
> it say that my key lenght is wrong.
> 
> Using:
> Print "K :" & Cipher["DES3"].KeyLength
> Print "IV:" & Cipher["DES3"].IvLength
> 
> I found that key length is 24 and iv is 8 but I have a key length of 48 
> and a iv of 16 and shell openssl get those without any
> problem.
> 
> Is that a bug ?
> 
> Thanks in advence,
> Marco.
> 
> 
> 
> Il 30/05/23 17:59, Marco Ancillotti ha scritto:
>>
>> Hi all.
>>
>> I'm trying to replicate a des3 encryption without shell using only 
>> gambas but I get different output.
>>
>> This is my example code:
>>
>> #!/usr/bin/env gbs3
>>
>> USE "gb.openssl"
>>
>> ' Key
>> dim K as string="8aa69be1566a1dff572e102ed7266da674524d78ea8b933a"
>> ' Init Vector
>> dim IV as string="7eec1ceeaebc9828"
>> ' string to encrypt
>> dim pwd as string="1234567812345678"
>>
>> print Cipher["DES3"].EncryptSalted(pwd,K,IV)
>>
>> shell "printf \"" & pwd &  "\"" &
>>      " | openssl des3 -a -nopad " &
>>      "-K \"" & K & "\" " &
>>      "-iv \"" & IV & "\""
>>
>> I get the right output from the shell openssl call but I can't 
>> replicate with gambas.
>>
>> What's wrong ?
>>
>> thank's in advance,
>> marco.
>>

'gb.openssl' method arguments are bytes. Command-line 'openssl' 
arguments are hexadecimal digits. I guess this is the reason why you 
don't get the same results.

Regards,

-- 
Benoît Minisini.



More information about the User mailing list