Exemplo n.º 1
0
//initialize the cipher
func NewCipherCtx() *CipherCtx {
	ctx := CipherCtx{new(C.EVP_CIPHER_CTX)}
	C.EVP_CIPHER_CTX_init(ctx.evp_cipher_ctx)
	ctx.SetPadding(0)
	runtime.SetFinalizer(&ctx, CleanUpCipherCtx)
	return &ctx
}
Exemplo n.º 2
0
func New(key, iv []byte) Cipher {
	c := &cipher{}
	cgolock.Lock()
	defer cgolock.Unlock()

	C.EVP_CIPHER_CTX_init(&c.evp)
	runtime.SetFinalizer(c, func(c *cipher) {
		C.EVP_CIPHER_CTX_cleanup(&c.evp)
	})

	C.EVP_EncryptInit_ex(&c.evp, C.EVP_aes_128_ctr(), nil, (*C.uchar)(&key[0]), (*C.uchar)(&iv[0]))

	return c
}