title: "wrong final block length" when Ruby decrypts data encrypted by go
body: <p>I'm trying to encrypt a piece of data in Go and then store it into a database to be later pulled out and decrypted by Rails.</p>
  
  <p>Here is the Go encryption code:</p>
  
  <pre><code>func Encrypt(text []byte) ([]byte, error) {
    key := []byte("a very very very very secret key")
    block, err := aes.NewCipher(key)
  
    if err != nil {
      return nil, err
    }
  
    b := base64.StdEncoding.EncodeToString(text)
    ciphertext := make([]byte, aes.BlockSize+len(b))
    iv := ciphertext[:aes.BlockSize]
  
    if _, err := io.ReadFull(rand.Reader, iv); err != nil {
      return nil, err
    }
  
    cfb := cipher.NewCFBEncrypter(block, iv)
    cfb.XORKeyStream(ciphertext[aes.BlockSize:], []byte(b))
  
    return ciphertext, nil
  }
  </code></pre>
  
  <p>And here is my Ruby code to decrypt:</p>
  
  <pre><code>def decrypt(message)
    key = "a very very very very secret key"
  
    iv = message[0, 14]
    data = message[15, message.length+1]
  
    key = Digest::SHA256.digest(key) if(key.kind_of?(String) &amp;&amp; 32 != key.bytesize)
    iv = Digest::MD5.digest(iv) if(iv.kind_of?(String) &amp;&amp; 16 != iv.bytesize)
  
    aes = OpenSSL::Cipher.new('AES-256-CBC')
    aes.decrypt
    aes.key = key
    aes.iv = iv
    aes.update(data) + aes.final
  end
  </code></pre>
  
  <p>This is giving me an error message of:</p>
  
  <pre><code>OpenSSL::Cipher::CipherError: wrong final block length
  </code></pre>
  
  <p>Can anyone help let me know what I'm doing wrong?</p>
  
  <p>Thanks!</p>