Instruction

Phoenix.Crypto is a Phoenix JS tool to help us do text encryption and decryption in browser side by simple XOR cipher.

Include Crypto:

\Phoenix\Script\PhoenixScript::crypto();

Encrypt/Decrypt Text

var text = 'Windwalker';
var key = 'dfG9O34F';
var secret = Phoenix.Crypto.encrypt(key, text);

console.log(secret);
console.log(Phoenix.Crypto.decrypt(key, secret));

Output:

NTEsMTUsNDEsOTMsNTYsODIsODgsNDUsMSwyMA==
Windwalker

Base64

Simple methods to wrap btoa() and atob()

var base64 = Phoenix.Crypto.base64Encode('Hello');

console.log(base64);
console.log(Phoenix.Crypto.base64Decode(base64));

Output:

SGVsbG8=
Hello

MD5

A JS md5 implementation, will be useful if you need an identify when you generating elements in frontend.

Phoenix.Crypto.md5('Windwalker'); // fa0a731220e28af75afba7135723015e

UUID v4

UUID is useful if you need to generate random ID for dynamic elements.

Phoenix.Crypto.uuid4();

The result:

46a37daa-ef63-4b0c-9b4c-ec7008b19b70

If you found a typo or error, please help us improve this document.