Skip to content

Instantly share code, notes, and snippets.

@beepony
Created May 24, 2016 06:10
Show Gist options
  • Save beepony/e5b339b19c363e21d24246a70dd64299 to your computer and use it in GitHub Desktop.
Save beepony/e5b339b19c363e21d24246a70dd64299 to your computer and use it in GitHub Desktop.
#! /usr/bin/ruby -w
# encode and decode use ruby base64 lib
# use strict model to avoid "\n" problem every 76 characteres
require 'base64'
decode_string = Base64.strict_encode64(string)
encode_string = Base64.strict_decode64(string)
@beepony
Copy link
Author

beepony commented May 27, 2016

base64 编码默认每 76 个字符添加 \n,这往往导致字符串错误,可以使用严格的编码模式代替,Base64.strict_endcodee64(str)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment