Skip to content

Instantly share code, notes, and snippets.

@corerman
Created January 5, 2018 03:49
Show Gist options
  • Save corerman/bea1d181cdab146205f48a319d6961f9 to your computer and use it in GitHub Desktop.
Save corerman/bea1d181cdab146205f48a319d6961f9 to your computer and use it in GitHub Desktop.
golang blowfish 加密算法
package main
import (
"crypto/cipher"
// "github.com/labstack/gommon/log"
"golang.org/x/crypto/blowfish"
"fmt"
)
func main() {
// decrypt()
encrypt()
}
func decrypt( src []byte) {
key := []byte("corermankeycorermankey")
IV := []byte("iv123456")
ci, _ := blowfish.NewCipher(key)
// NewCFBDecrypter 和 NewCFBEncrypter 好像可以随便用
en := cipher.NewCFBDecrypter(ci, IV)
// en := cipher.NewCFBEncrypter(ci, IV)
data:= src
dst := make([]byte, len(data))
fmt.Println(string(data))
en.XORKeyStream(dst, data)
fmt.Println(string(dst))
}
func encrypt() {
key := []byte("corermankeycorermankey")
IV := []byte("iv123456")
ci, _ := blowfish.NewCipher(key)
// NewCFBDecrypter 和 NewCFBEncrypter 好像可以随便用
en := cipher.NewCFBDecrypter(ci, IV)
// en := cipher.NewCFBEncrypter(ci, IV)
data := []byte("corerman")
dst := make([]byte, len(data))
en.XORKeyStream(dst, data)
decrypt(dst)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment