将加密方式替换为AES-CTRpackage utilimport cryptoaes cryptocipherfunc newAeadkey byte cipherAEAD error block err = aesNewCipherkey if err != nil return nil err aead err = cipherNewGCMblock if err != nil
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 }
原文地址: https://www.cveoy.top/t/topic/ZNH 著作权归作者所有。请勿转载和采集!