Cipher:encrypt(data) method
Encrypt the specified data.
Parameters
data
A Buffer or a string containing the data to be encrypted. The Cipher object uses an internal encryption buffer, so that sucessive calls to this method appends the encrypted data to this internal buffer. That permits to encrypt data from various streams easily.
Use the property Cipher.encrypted to retrieve the whole encrypted data.
Return value
Returns the number of bytes encrypted.Example
-- File encryption
local crypto = require "crypto"
local console = require "console"
local cipher = crypto.Cipher("aes128", "its_a_secret_key")
-- encrypt file
local file = sys.File(console.readln("Enter the file to encrypt: "))
print("Successfully encrypted "..cipher:encrypt(file:open():read()).." bytes")
-- generate the encrypted file
sys.File("encrypted.dat"):open("write"):write(cipher.encrypted)