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 }
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 }
func InitCipher(token string) { TokenMD5 = MD5(token) Cipher, _ = blowfish.NewCipher([]byte(token)) }