spacemonkeygo / openssl

OpenSSL bindings for Go
http://godoc.org/github.com/spacemonkeygo/openssl
Apache License 2.0
472 stars 237 forks source link

encrypt using this package doesn't give the same result as with openssl command #63

Closed dellarte closed 7 years ago

dellarte commented 8 years ago

I'm trying to encipher my data using this function (which is available here)

func (c *Crypter) Encrypt(input []byte) ([]byte, error) {
  ctx, err := openssl.NewEncryptionCipherCtx(c.cipher, nil, c.key, c.iv)
  if err != nil {
    return nil, err
  }

  cipherbytes, err := ctx.EncryptUpdate(input)
  if err != nil {
    return nil, err
  }

  finalbytes, err := ctx.EncryptFinal()
  if err != nil {
    return nil, err
  }

  cipherbytes = append(cipherbytes, finalbytes...)
  return cipherbytes, nil
}

But the result is not the same as if i try then openssl command. So, Finally decryption doesn't work as well.

I think the problem went from the use of []byte key instead of string key.

zeebo commented 7 years ago

I'm sorry this doesn't work the same for you, but it sounds like a difference between the command line and how the C interface we've wrapped is being used. The []byte vs string will make no difference because we have to copy either to a C string before we pass it anyway.

Please check the openssl documentation to resolve your issue.