예제 #1
0
func CBCDecrypt(ct, key, iv []byte) []byte {

	blow, _ := blowfish.NewCipher(key)
	defer blow.Reset()
	bz := blow.BlockSize()

	dc := make([]byte, len(ct))
	for i := 0; i < len(ct); i += bz {

		blow.Decrypt(ct[i:i+bz], dc[i:i+bz])

		for j := 0; j < bz; j++ {
			dc[i+j] ^= iv[j]

		}
		iv = ct[i : i+bz]

	}

	decrypted := depadd(dc)
	return decrypted
}
예제 #2
0
func CBCEncrypt(pt, key, iv []byte) []byte {

	blow, _ := blowfish.NewCipher(key)
	defer blow.Reset()
	bz := blow.BlockSize()

	padded := padd(pt, byte(bz))
	encrypted := make([]byte, len(padded))

	for i := 0; i < len(padded); i += bz {

		for j := 0; j < bz; j++ {
			padded[i+j] ^= iv[j]

		}

		blow.Encrypt(padded[i:i+bz], encrypted[i:i+bz])

		iv = encrypted[i : i+bz]
	}

	return encrypted
}
예제 #3
0
파일: gg.go 프로젝트: zbq/gg
func InitCipher(token string) {
	TokenMD5 = MD5(token)
	Cipher, _ = blowfish.NewCipher([]byte(token))
}