mirror of
https://github.com/remotely-save/remotely-save.git
synced 2024-06-07 21:10:45 +00:00
test for enc
This commit is contained in:
parent
ec2fec9bf8
commit
8fbbae6c2e
5
.gitattributes
vendored
Normal file
5
.gitattributes
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
*.png filter=lfs diff=lfs merge=lfs -text
|
||||
*.jpg filter=lfs diff=lfs merge=lfs -text
|
||||
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
||||
*.pdf filter=lfs diff=lfs merge=lfs -text
|
||||
*.enc filter=lfs diff=lfs merge=lfs -text
|
@ -0,0 +1,3 @@
|
||||
The file 1374px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg is downloaded from Wikimedia Commons: https://commons.wikimedia.org/wiki/File:Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg .
|
||||
|
||||
Quoted from the web address: ... This photographic reproduction is therefore also considered to be in the public domain in the United States. In other jurisdictions, re-use of this content may be restricted ...
|
BIN
tests/static_assets/mona_lisa/1374px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg
(Stored with Git LFS)
Normal file
BIN
tests/static_assets/mona_lisa/1374px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
tests/static_assets/mona_lisa/1374px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg.enc
(Stored with Git LFS)
Normal file
BIN
tests/static_assets/mona_lisa/1374px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg.enc
(Stored with Git LFS)
Normal file
Binary file not shown.
3
tests/static_assets/mona_lisa/openssl_command.sh
Normal file
3
tests/static_assets/mona_lisa/openssl_command.sh
Normal file
@ -0,0 +1,3 @@
|
||||
# The encryption file is produced by the following command.
|
||||
# A salt is explictly provided because we need reproducible output in tests.
|
||||
openssl enc -p -aes-256-cbc -S 8302F586FAB491EC -pbkdf2 -iter 10000 -pass pass:somepassword -in '1374px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg' -out 1374px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg.enc
|
@ -1,8 +1,11 @@
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import { expect } from "chai";
|
||||
import { base64ToBase32 } from "../src/misc";
|
||||
import { base64ToBase32, bufferToArrayBuffer } from "../src/misc";
|
||||
import {
|
||||
decryptArrayBuffer,
|
||||
decryptBase32ToString,
|
||||
encryptArrayBuffer,
|
||||
encryptStringToBase32,
|
||||
} from "../src/encrypt";
|
||||
|
||||
@ -29,9 +32,11 @@ describe("Encryption tests", () => {
|
||||
expect(dec).equal(k);
|
||||
});
|
||||
|
||||
it("should encrypt and get the same result as openssl", async () => {
|
||||
it("should encrypt text file and get the same result as openssl", async () => {
|
||||
const fileContent = (
|
||||
await fs.readFileSync(__dirname + "/sometext.txt")
|
||||
await fs.readFileSync(
|
||||
path.join(__dirname, "static_assets", "sometext.txt")
|
||||
)
|
||||
).toString("utf-8");
|
||||
const password = "somepassword";
|
||||
const saltHex = "8302F586FAB491EC";
|
||||
@ -52,4 +57,42 @@ describe("Encryption tests", () => {
|
||||
|
||||
expect(enc).equal(opensslBase32Res);
|
||||
});
|
||||
|
||||
it("should encrypt binary file and get the same result as openssl", async () => {
|
||||
const testFolder = path.join(__dirname, "static_assets", "mona_lisa");
|
||||
const testFileName =
|
||||
"1374px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg";
|
||||
const fileArrBuf = bufferToArrayBuffer(
|
||||
await fs.readFileSync(path.join(testFolder, testFileName))
|
||||
);
|
||||
const password = "somepassword";
|
||||
const saltHex = "8302F586FAB491EC";
|
||||
const enc = await encryptArrayBuffer(
|
||||
fileArrBuf,
|
||||
password,
|
||||
undefined,
|
||||
saltHex
|
||||
);
|
||||
const opensslArrBuf = bufferToArrayBuffer(
|
||||
await fs.readFileSync(path.join(testFolder, testFileName + ".enc"))
|
||||
);
|
||||
|
||||
expect(Buffer.from(enc).equals(Buffer.from(opensslArrBuf))).to.be.true;
|
||||
});
|
||||
|
||||
it("should descypt binary file and get the same result as openssl", async () => {
|
||||
const testFolder = path.join(__dirname, "static_assets", "mona_lisa");
|
||||
const testFileName =
|
||||
"1374px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg";
|
||||
const fileArrBuf = bufferToArrayBuffer(
|
||||
await fs.readFileSync(path.join(testFolder, testFileName + ".enc"))
|
||||
);
|
||||
const password = "somepassword";
|
||||
const dec = await decryptArrayBuffer(fileArrBuf, password);
|
||||
const opensslArrBuf = bufferToArrayBuffer(
|
||||
await fs.readFileSync(path.join(testFolder, testFileName))
|
||||
);
|
||||
|
||||
expect(Buffer.from(dec).equals(Buffer.from(opensslArrBuf))).to.be.true;
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user