Experience address:https://jrainlau.github.io/sp …
Project address:https://github.com/jrainlau/s …
SphinxJS
An ultra-light open source library that can encode strings into png pictures or decode strings from png pictures, with the total number of codes not exceeding 100 lines!
Use method
vianpm
Installation
npm install sphinx.js
via<script></script>
Label introduction
<script src="sphinx.js"></script>
It is worth noting that because
SphinxJS
Using ES2015Promise
As well as other great features, which means your browser is required to provide support. Otherwise, you may need toBabel
Or some other tool to build your code.
SphinxJS
At the same time support toAMD
,CommonJS
as well asES6 module
To be used as a reference.
Coding
Define a stringHello Sphinx!
, we will encode it
let base64URL = new Sphinx().encode('Hello Sphinx!' )
Then you will get a stringbase64
Coding
data:image/png; base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAADCAYAAABWKLW/AAAAJklEQVQYV2P0SM35r8K1heE5owcDY2Zexf8dc1Yw/BdjYGBkQAIA+r4JjQKvLx4AAAAASUVORK5CYII=
At this step, the coding has been completed.
As you can see,encode()
The method returns the of a picturebase64
Code.
Decoding
Url defining a string of pictures:
let url = 'data:image/png; base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAADCAYAAABWKLW/AAAAJklEQVQYV2P0SM35r8K1heE5owcDY2Zexf8dc1Yw/BdjYGBkQAIA+r4JjQKvLx4AAAAASUVORK5CYII='
Then we decode it!
new Sphinx().decode(url)
.then((info) => {
console.log(info) // Hello Sphinx!
})
decode()
The method returns aPromise
Object that contains string information decrypted from the picture.
Configuration
new Sphinx()
Can receive a configuration object for defining picture types
-
config {Object}
Optional
Default value:{img: 'png'}
new Sphinx({img: 'bmp'})
Certificate
MIT