Created
January 5, 2018 03:49
-
-
Save corerman/bea1d181cdab146205f48a319d6961f9 to your computer and use it in GitHub Desktop.
golang blowfish 加密算法
This file contains 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 ( | |
"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