import CryptoJS from 'crypto-js'

const defaultKey = 'f080a463654b2279';

export function encrypt(word, keyStr = defaultKey) {
	const key = CryptoJS.enc.Utf8.parse(keyStr);
	const src = CryptoJS.enc.Utf8.parse(word);
	const encrypted = CryptoJS.AES.encrypt(src, key, {
		mode: CryptoJS.mode.ECB,
		padding: CryptoJS.pad.Pkcs7,
	});
	return encrypted.toString();
}

export function decrypt(word, keyStr = defaultKey) {
	const key = CryptoJS.enc.Utf8.parse(keyStr);
	const decrypt = CryptoJS.AES.decrypt(word, key, {
		mode: CryptoJS.mode.ECB,
		padding: CryptoJS.pad.Pkcs7,
	});
	return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}
