title: golang illegal base64 data at input byte 0
body: <p>I have a go test program to read encrypted content from file and decrypt it, but it get output like below:</p>
  
  <p>illegal base64 data at input byte 0</p>
  
  <p>if  I hard code the encrypted content in a golang string variable, it can decrypt it fine. what I am missing here? I searched similar error in stackoverflow, there is similar report, but not exact the same problem I have. the test code like below:</p>
  
  <pre><code>package main
  
  import (
  "crypto/aes"
  "crypto/cipher"
  "crypto/rand"
  "encoding/base64"
  "errors"
  "fmt"
  "io"
  "bufio"
  "os"
  "log"
  
  )
  
  
  func check(e error) {
      if e != nil {
          panic(e)
      }
  }
  
  func main() {
      plaintext := []byte("textstring")
      key := []byte("a very very very very very secre")
      fmt.Printf("%s\n", plaintext)
  
      fh, err := os.Open("./test.txt")
      check(err)
      scanner := bufio.NewScanner(fh)
      var encrypted_text string
      if scanner.Scan() { //&lt;==========READ FROM FILE
      encrypted_text = scanner.Text()
          fmt.Println("encrypted_text from file: ", encrypted_text)
      } else { //&lt;===========HARD CODE HERE
          encrypted_text  = "\xf2F\xbc\x15\x9d\xaf\xceϘ\xa3L(&gt;%\xa2\x94\x03_\x99\u007fG\xd8\v\xbf\t#u\xf8:\xc0D\u007f"
          fmt.Println("encrypted_text hard coded: ", encrypted_text)
      }
  
      encrypted_byte  := []byte(encrypted_text)
      fmt.Printf("encrypted_byte: %s\n", encrypted_byte)
      result, err := decrypt(key, encrypted_byte)
      if err != nil {
          log.Fatal(err)
      }
      fmt.Printf("result %s\n", string(result))
  }
  
  func encrypt(key, text []byte) ([]byte, error) {
      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
  }
  
  func decrypt(key, text []byte) ([]byte, error) {
      block, err := aes.NewCipher(key)
      if err != nil {
          return nil, err
      }
      if len(text) &lt; aes.BlockSize {
          return nil, errors.New("ciphertext too short")
      }
      iv := text[:aes.BlockSize]
      text = text[aes.BlockSize:]
      cfb := cipher.NewCFBDecrypter(block, iv)
      cfb.XORKeyStream(text, text)
      data, err := base64.StdEncoding.DecodeString(string(text))
      if err != nil {
          return nil, err
      }
      return data, nil
  }
  </code></pre>