[Up]: Storage API : Encrypt

File Encryption

Script path: /storage/bin/api/encrypt.cgi

Description:  Encrypt specified file(s) using a given password / passphrase as the key

INPUT (via GET or POST)

   sid => the authenticated session id  (must be valid)

path => the path to the file

Multiple paths can be specified by repeating this parameter.

(Current implementation accepts path to a file only. If the path specifies a folder, it will abort.)

path_list => JSON list of paths

Format of the JSON object is as follows:
{
"path_list" : [ path1, path2, path3 ...]
}

An alternative way to specify one or more paths. The path(s) here will merge with it the previous parameter.

(Current implementation accepts path to a file only. If the path specifies a folder, it will abort.)

passwd => password or passphrase, limited to 255 characters, alphanumerics, underscores, spaces only

delete_original => yes

The original file will be DELETED after successful encryption.
By default the original will NOT be deleted.

replace_existing_enc => yes

IF there is an existing encrypted file for a given item, it will be removed and recreated.
By default this will not done.

ofmt => output format defaults to JSON format with minimal white spaces.
ofmt = jsonp means to produce JSON format in pretty printed way (easier to read)


OUTPUT (content-type: text/plain)


   JSON output object for general successful case, where each file gets encrypted.
However, the result_list needs to be inspected to see if processing result for EACH file.
result = "OK" | "FAIL" (for successful encryption or not)

{
"status" : true,
"result_list" : [
{
"itemname" : "/Private/testfolder/Български/NewFile您可以使用这个.txt",
"comments" : "",
"result" : "OK"
},
{
"itemname" : "/Private/testfolder/Български Espaņol.txt",
"comments" : "Encryption aborted because there already exist a file named Български Espaņol.txt.enc",
"result" : "FAIL"
}
]
}



JSON output object for general unsuccessful case:

{
"status" : false,
"errmsg" : "(reason for failure)"
}

e.g.
{
"status" : false,
"errmsg" : "PassPhrase is empty"
}

In all cases, appropriate HTTP header status codes are also returned e.g. 200 OK, 401 Invalid user
profile, etc.


NOTES:

A new encrypted version of a file will be created for each file specified in the path parameter.
This encrypted file has the same name as the original but will end with ".enc".
By default the original file will not be deleted. If there is an existing ".enc" file for
the encrypted original file, by default, it will not be replaced/overwritten.

e.g. SomeFile.txt will be encrypted as SomeFile.txt.enc

The file timestamp of the encrypted file will be made the same as the original's.

The .enc file extension is reserved for encrypted files. So, this API will not encrypt a file that
already has the .enc file extension.

WARNING: The encryption password is not stored anywhere and it cannot be recovered or reset for the user.
Give appropriate warning to the end-user.