How to convert avoiding parser

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to convert avoiding parser

CdAB63
Hello,

Perhaps someone can help me with this problem: I'm saving a key pair in
a mariadb/mysql table as follows:

     str := 'INSERT INTO chaves_de_encriptacao (numero_funcional,
chave_privada, chave_publica) '.
     str := str,'VALUES ('''.
     str := str, self personId leaId asString, ''', '''.
     str := str, self keyPair privateKey asAsn1DerBytes asByteArray hex,
''', '''.
     str := str, self keyPair publicKey  asAsn1DerBytes asByteArray
hex,''')'.

     [ dbConnection execute: str ] on: Exception do: [ ^ false ].

And I'd like to recover the keys (SELECT * FROM chaves_de_encriptacao
WHERE numero_funcional = 1010) and then reconvert in order to recover
the original keys. Obviously I can do that by writting a parser that
will get the hex and bring it back to binary but I'd like to avoid it.

Question is: is there a reverse for asByteArray hex?


Reply | Threaded
Open this post in threaded view
|

Re: How to convert avoiding parser

Sven Van Caekenberghe-2

> On 13 Sep 2017, at 19:44, Casimiro de Almeida Barreto <[hidden email]> wrote:
>
> Hello,
>
> Perhaps someone can help me with this problem: I'm saving a key pair in a mariadb/mysql table as follows:
>
>     str := 'INSERT INTO chaves_de_encriptacao (numero_funcional, chave_privada, chave_publica) '.
>     str := str,'VALUES ('''.
>     str := str, self personId leaId asString, ''', '''.
>     str := str, self keyPair privateKey asAsn1DerBytes asByteArray hex, ''', '''.
>     str := str, self keyPair publicKey  asAsn1DerBytes asByteArray hex,''')'.
>
>     [ dbConnection execute: str ] on: Exception do: [ ^ false ].
>
> And I'd like to recover the keys (SELECT * FROM chaves_de_encriptacao WHERE numero_funcional = 1010) and then reconvert in order to recover the original keys. Obviously I can do that by writting a parser that will get the hex and bring it back to binary but I'd like to avoid it.
>
> Question is: is there a reverse for asByteArray hex?

Yes:

ByteArray readHexFrom: #[ 0 1 2 3 4 5 6 7 8 9 10 ] hex.

HTH,

Sven



Reply | Threaded
Open this post in threaded view
|

Re: How to convert avoiding parser

Esteban A. Maringolo
Hi,

Side note: Please sanitize the strings you use for the concatenation
or use prepared statements, otherwise you could be vulnerable to SQL
INJECTION attacks.

Best regards,

Esteban A. Maringolo


2017-09-13 17:34 GMT-03:00 Sven Van Caekenberghe <[hidden email]>:

>
>> On 13 Sep 2017, at 19:44, Casimiro de Almeida Barreto <[hidden email]> wrote:
>>
>> Hello,
>>
>> Perhaps someone can help me with this problem: I'm saving a key pair in a mariadb/mysql table as follows:
>>
>>     str := 'INSERT INTO chaves_de_encriptacao (numero_funcional, chave_privada, chave_publica) '.
>>     str := str,'VALUES ('''.
>>     str := str, self personId leaId asString, ''', '''.
>>     str := str, self keyPair privateKey asAsn1DerBytes asByteArray hex, ''', '''.
>>     str := str, self keyPair publicKey  asAsn1DerBytes asByteArray hex,''')'.
>>
>>     [ dbConnection execute: str ] on: Exception do: [ ^ false ].
>>
>> And I'd like to recover the keys (SELECT * FROM chaves_de_encriptacao WHERE numero_funcional = 1010) and then reconvert in order to recover the original keys. Obviously I can do that by writting a parser that will get the hex and bring it back to binary but I'd like to avoid it.
>>
>> Question is: is there a reverse for asByteArray hex?
>
> Yes:
>
> ByteArray readHexFrom: #[ 0 1 2 3 4 5 6 7 8 9 10 ] hex.
>
> HTH,
>
> Sven
>
>
>