[Gambas-user] Usage of openssl.EncryptSalted

Marco Ancillotti gambas at servinfo.it
Wed May 31 19:21:36 CEST 2023


Hi all ,

i'm really near , I converted all data and it works but I need the 
output with option -nopad , as openssl say it: "Disable standard block 
padding" , is there an option on gambas to enable it ?

This is my 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"
dim s as string

' Run shell script to see Wanted result
print "Value I need: (with nopad)"
shell "printf \"" & pwd &  "\"" &
      " | openssl des3 -a -nopad " &
      "-K \"" & K & "\" " &
      "-iv \"" & IV & "\"" wait

print "\nValue I don't need: (without nopad)"
shell "printf \"" & pwd &  "\"" &
      " | openssl des3 -a " &
      "-K \"" & K & "\" " &
      "-iv \"" & IV & "\"" wait

' Convert Key from hex to string
for i as Integer = 0 to 47 step 2
    s &= chr(val("&" & mid$(K,i+1,2) & "&"))
next
K = s
s = ""

' Convert IV from hex to string
for i as Integer = 0 to 15 step 2
    s &= chr(val("&" & mid$(IV,i+1,2) & "&"))
next
IV = s

' Print Result
print "\nValue I get: (same without nopad)"
print base64(Cipher["DES3"].Encrypt(pwd,K,IV).Cipher)

It's the output:

Value I need: (with nopad)
M39hm3jXarZcAkVmVMq/Rw==

Value I don't need: (without nopad)
M39hm3jXarZcAkVmVMq/R0xR/rJnKy7P

Value I get: (same without nopad)
M39hm3jXarZcAkVmVMq/R0xR/rJnKy7P

Thank's all ,
marco.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230531/62978265/attachment.htm>


More information about the User mailing list