Skip to content

Commit b79f1ce

Browse files
Example Added
1 parent e963e7f commit b79f1ce

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Object-Encryption-In-Javascript
2+
The project shows how to directly encode object without converting it to string, this is written in plain Javascript, no any other file required and it is not dependent of anything.
3+
You can download this and check that how to use this methods.<br />
4+
to clone this project simply run: <br/>
5+
6+
<pre>git clone https://github.com/sbamniya/Object-Encryption-In-Javascript.git</pre>
7+
Optionally you can also download Zip of the same.
8+
9+
Add <code>ObjectBase64.js</code> file to your project.
10+
11+
It's pretty simple.
12+
13+
# Encrypt Object
14+
After adding the required file all you need to do is call the encryption function, like below:
15+
16+
<pre>var encryptedObj = ObjEncrypt(Object, Salt)</pre>
17+
18+
# Dencrypt Object
19+
After adding the required file all you need to do is call the decryption function, like below:
20+
21+
<pre>var decryptedObj = ObjDecrypt(encryptedObj, Salt)</pre>

index.html

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Object Encryption</title>
5+
</head>
6+
<body>
7+
<h3>Original Obeject</h3>
8+
<code id="original">
9+
10+
</code>
11+
<h3>Encrypted Object</h3>
12+
<code id="encrypt">
13+
14+
</code>
15+
<h3>Decrypted Object</h3>
16+
<code id="decypt">
17+
18+
</code>
19+
</body>
20+
<script type="text/javascript" src="src/ObjectBase64.js"></script>
21+
<script type="text/javascript">
22+
var originalElement = document.getElementById('original');
23+
var encryptElement = document.getElementById('encrypt');
24+
var descyptElement = document.getElementById('decypt');
25+
26+
var obj = {
27+
"glossary": {
28+
"title": "example glossary",
29+
"GlossDiv": {
30+
"title": "S",
31+
"GlossList": {
32+
"GlossEntry": {
33+
"ID": "SGML",
34+
"SortAs": "SGML",
35+
"GlossTerm": "Standard Generalized Markup Language",
36+
"Acronym": "SGML",
37+
"Abbrev": "ISO 8879:1986",
38+
"GlossDef": {
39+
"para": "A meta-markup language, used to create markup languages such as DocBook.",
40+
"GlossSeeAlso": ["GML", "XML"]
41+
},
42+
"GlossSee": "markup"
43+
}
44+
}
45+
}
46+
}
47+
}
48+
var salt = "some string here";
49+
50+
originalElement.innerHTML = JSON.stringify(obj);
51+
52+
var encrypted = ObjEncrypt(obj, salt);
53+
encryptElement.innerHTML = encrypted;
54+
55+
var decrypted = ObjDecrypt(encrypted, salt);
56+
descyptElement.innerHTML = JSON.stringify(decrypted);
57+
</script>
58+
</html>

src/ObjectBase64.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)