0

I have an encrypted string that I was able to decrypt in nodejs using the following code

let decrypt = crypto.createDecipheriv('aes-256-cbc-hmac-sha1', derived, iv);
decrypt.setAutoPadding(false);
let decrypted = decrypt.update(new_buf, 'binary', 'utf8') + decrypt.final('utf8');

I have to be able to decrypt the same buffer in a go program and I wrote this

fmt.Printf("buf size=%d\n", len(derivedKey))
block, err := aes.NewCipher(derivedKey)
if err != nil {
    fmt.Printf("%v\n", err)
    return ("0")
}
fmt.Printf("block size=%d\n", block.BlockSize())
cbc := cipher.NewCBCDecrypter(block, ivKey)
fmt.Printf("cbc block size=%d\n", cbc.BlockSize())
decr := make([]byte, len(encr))
cbc.CryptBlocks(decr, []byte(encr))

This isn't working (I suppose I won't be posting here otherwise :p) but I also noticed that when I print the length of the derived key I get 32 but when I read the block.BlockSize() or the cbc.BlockSize() I get 16 as an answer so I'm wondering if I don't have to setup something because it is detecting my algorithm as aes128 instead of aes256.

1
  • Please fix your title spelling: when you write ecryption, do you mean "decryption" or "encryption"? Commented Jun 26, 2018 at 9:00

1 Answer 1

1

Ok this is working well actually, the blocksize show isn't a problem, internally it creates the correct block for the aes256, my problem was because of the parameters sent to me that added padding on the "encr" variable. But the code on top works perfectly

Sign up to request clarification or add additional context in comments.

2 Comments

May I suggest, if you have an example of change, post it in your answer. As you said "a few posts... same problem". It can go a long way.
I'm sorry i'm not sure what you mean by change, i read those posts amoung others (stackoverflow.com/questions/46475204/…) and (stackoverflow.com/questions/46475204/…) but they weren't fully related to my problem, tho now i'm exploring how to remove padding. This was easy in node but in golang i can't do only a parseInt(numWithPadding, 10).toString() :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.