// AESEncrypt joins parts using sep, encrypts and seals it and returns b64 string.
// valid sizes are 16, 24 and 32 for AES-128, 192 and 256 respectively, defaults to 16.
AESEncrypt joins parts using sep, encrypts and seals it and returns b64 string.
valid sizes are 16, 24 and 32 for AES-128, 192 and 256 respectively, defaults to 16.
// AESEncrypt joins parts using sep encrypts and seals it and returns b64 string . // valid sizes are 16 24 and 32 for AES - 128 192 and 256 respectively defaults to 16 .
func AESEncrypt(parts []string, sep string, passphrase string, keySize uint8) (_ string, err error) {
	var (
		block cipher.Block
		gcm   cipher.AEAD
		sz    = len(sep) * len(parts)
		buf   = encBP.Get()
	)
	defer encBP.Put(buf)
	if block, err = aes.NewCipher(hash(passphrase, keySize)); err != nil {
		return
	}
	if gcm, err = cipher.NewGCM(block); err != nil {
		return
	}
	nonce := make([]byte, gcm.NonceSize())
	if _, err = io.ReadFull(rand.Reader, nonce); err != nil {
		return
	}
	for _, p := range parts {
		sz += len(p)
	}
	buf.Grow(sz)
	for i, p := range parts {
		if i > 0 {
			buf.WriteString(sep)
		}
		buf.WriteString(p)
	}
	enc := gcm.Seal(nonce, nonce, buf.Bytes(), nil)
	return base64.RawURLEncoding.EncodeToString(enc), nil
}
func AESEncrypt ( parts [ ] string , sep string , passphrase string , keySize uint8 ) ( _ string , err error ) { var ( block cipher . Block gcm cipher . AEAD sz = len ( sep ) * len ( parts ) buf = encBP . Get ( ) ) defer encBP . Put ( buf ) if block , err = aes . NewCipher ( hash ( passphrase , keySize ) ) ; err != nil { return } if gcm , err = cipher . NewGCM ( block ) ; err != nil { return } nonce := make ( [ ] byte , gcm . NonceSize ( ) ) if _ , err = io . ReadFull ( rand . Reader , nonce ) ; err != nil { return } for _ , p := range parts { sz += len ( p ) } buf . Grow ( sz ) for i , p := range parts { if i > 0 { buf . WriteString ( sep ) } buf . WriteString ( p ) } enc := gcm . Seal ( nonce , nonce , buf . Bytes ( ) , nil ) return base64 . RawURLEncoding . EncodeToString ( enc ) , nil }
AESEncrypt joins parts using sep, encrypts and seals it and returns b64 string.
AESEncrypt joins parts using sep encrypts and seals it and returns b64 string .