nimcrypto
nimcrypto copied to clipboard
endless recursion
hey,
I have a super weird bug, I wrote two functions: encrypt_cbc
and decrypt_cbc
- they both get (string, key, iv)
and do their job great.
Whenever I'm importing winim/clr
to the program (Winim) - context.init(key, iv)
calls the clr which invokes an endless recursion, which crashes the program..
the functions:
proc encrypt_cbc(plain_text: string, key: string, iv: string): string =
var ectx: CBC[aes256]
var cipher_text = newString(aes256.sizeBlock * 2)
var plain_text_padded = plain_text
while len(plain_text_padded) mod 32 != 0:
plain_text_padded = plain_text_padded & " "
ectx.init(key, iv)
ectx.encrypt(plain_text_padded, cipher_text)
ectx.clear()
return cipher_text
proc decrypt_cbc(cipher_text: string, key: string, iv: string): string =
var dctx: CBC[aes256]
var plain_text = newString(aes256.sizeBlock * 2)
dctx.init(key, iv)
dctx.decrypt(cipher_text, plain_text)
dctx.clear()
while plain_text.endsWith(" "):
plain_text.removeSuffix(" ")
return plain_text
thanks in advance, Itay