EVAL
/* * pure sync type otpus encryption */ let msg = 'this is top secret message'; let key = 'this is a secret key'; let encoded = otpus.encryptMessage( msg, key , 10); // 2 ** 10 => 1024 times prn('base64-encoded', encoded) let decoded = otpus.decryptMessage( encoded , key ) prn('decoded', decoded) /* * async type otpus encryption using Web Crypto API */ const Buffer = otpus.Buffer const MBP = otpus.MBP const encrypt = otpus.encrypt const decrypt = otpus.decrypt console.log( 'MBP.MB', MBP.MB('bf',32,0 )) // case1. string data const strData = 'hello world' encrypt(strData, key) .then(secretPack => { prn('random secretPack size', secretPack.byteLength) return decrypt(secretPack, key) }) .then(data => { prn('return data type is type of originData', typeof data ) // string prn('decoded string message: ', data) }) // case2. binary data const binaryData = Uint8Array.from([1, 2, 3, 4]) encrypt(binaryData, key) .then(secretPack => { prn('random secretPack size', secretPack.byteLength) return decrypt(secretPack, key) }) .then(data => { prn('instanceof Uint8Array:', data instanceof Uint8Array ) //true prn('decoded binary data: ', MBP.hex( data )) })
result: