Created
May 24, 2017 09:46
-
-
Save mpfund/7f02f2190dfa59bfd48c466531aa8651 to your computer and use it in GitHub Desktop.
encode/decode file base64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import( b64 "encoding/base64" | |
"fmt" | |
"log" | |
"flag" | |
"io/ioutil" | |
) | |
func main() { | |
decFlag := flag.Bool("dec", false, "decode instead of encode base64") | |
fileName := flag.String("f", "" , "input file") | |
flag.Parse() | |
// Here's the `string` we'll encode/decode. | |
data,err := ioutil.ReadFile(*fileName) | |
if err != nil{ | |
log.Fatal(err) | |
} | |
if(!*decFlag){ | |
sEnc := b64.StdEncoding.EncodeToString(data) | |
fmt.Println(sEnc) | |
}else{ | |
sDec, err := b64.StdEncoding.DecodeString(string(data)) | |
if err != nil{ | |
log.Fatal(err) | |
} | |
fmt.Println(string(sDec)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment