package util

import ( 'crypto/aes' 'crypto/cipher' )

func newStream(key []byte, nonce []byte) cipher.Stream { block, _ := aes.NewCipher(key) stream := cipher.NewCTR(block, nonce) return stream }

func E(plain []byte, key, nonce []byte) []byte { stream := newStream(key, nonce) cipherText := make([]byte, len(plain)) stream.XORKeyStream(cipherText, plain) return cipherText }

func D(cipher []byte, key, nonce []byte) []byte { stream := newStream(key, nonce) plainText := make([]byte, len(cipher)) stream.XORKeyStream(plainText, cipher) return plainText }

Go语言中使用AES-CTR加密解密算法

原文地址: https://www.cveoy.top/t/topic/mkdu 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录