Skip to content

Commit 169b233

Browse files
carpecodeumsumedhe
andauthored
Add backend for client sample of react-native, added logger, connection to switch and sender receiver function along with aesutils, added react-native interface for sender device (#188)
Co-authored-by: Sumedhe Dissanayake <[email protected]>
1 parent 8ecf05b commit 169b233

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+3757
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# Xcode
6+
#
7+
build/
8+
*.pbxuser
9+
!default.pbxuser
10+
*.mode1v3
11+
!default.mode1v3
12+
*.mode2v3
13+
!default.mode2v3
14+
*.perspectivev3
15+
!default.perspectivev3
16+
xcuserdata
17+
*.xccheckout
18+
*.moved-aside
19+
DerivedData
20+
*.hmap
21+
*.ipa
22+
*.xcuserstate
23+
24+
# node.js
25+
#
26+
node_modules/
27+
npm-debug.log
28+
yarn-error.log
29+
30+
# BUCK
31+
buck-out/
32+
\.buckd/
33+
*.keystore
34+
!debug.keystore
35+
36+
# fastlane
37+
#
38+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
39+
# screenshots whenever they are needed.
40+
# For more information about the recommended setup visit:
41+
# https://docs.fastlane.tools/best-practices/source-control/
42+
43+
*/fastlane/report.xml
44+
*/fastlane/Preview.html
45+
*/fastlane/screenshots
46+
47+
# Bundle artifact
48+
*.jsbundle
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const aesjs = require("aes-js");
2+
const base64js = require("base64-js");
3+
const ab2str = require("arraybuffer-to-string");
4+
5+
class AESUtils {
6+
constructor(key) {
7+
this.bs = 32;
8+
this.key = key;
9+
}
10+
encrypt(raw) {
11+
//Message should be a multiple of 16 bytes
12+
raw = this.pad(raw);
13+
// The initialization vector (must be 16 bytes)
14+
const iv = [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36];
15+
//Convert text to bytes
16+
const textBytes = aesjs.utils.utf8.toBytes(raw);
17+
const aesCbc = new aesjs.ModeOfOperation.cbc(this.key, iv);
18+
//Encrypt the message
19+
const encryptedBytes = aesCbc.encrypt(textBytes);
20+
const encryptedBytesBase64 = base64js.fromByteArray(encryptedBytes);
21+
return encryptedBytesBase64;
22+
}
23+
decrypt(enc) {
24+
const iv = [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36];
25+
const encryptedBytes = base64js.toByteArray(enc);
26+
const aesCbc = new aesjs.ModeOfOperation.cbc(this.key, iv);
27+
//Get the decrypted bytes
28+
const decryptedBytes = aesCbc.decrypt(encryptedBytes);
29+
//Convert the decrypted bytes to text
30+
const uint8 = new Uint8Array(decryptedBytes);
31+
const decryptedText = ab2str(uint8);
32+
return this.unpad(decryptedText);
33+
}
34+
ord(str) {
35+
return str.charCodeAt(0);
36+
}
37+
38+
pad(s) {
39+
let fins = "";
40+
const num = this.bs - (s.length % this.bs);
41+
for (let i = 0; i < num; i++) {
42+
fins = fins + String.fromCharCode(this.bs - (s.length % this.bs));
43+
}
44+
return s + fins;
45+
}
46+
unpad(s) {
47+
return s.substr(0, s.length - this.ord(s.substr(s.length - 1)));
48+
}
49+
}
50+
51+
module.exports = AESUtils;

0 commit comments

Comments
 (0)