How to Encode and Decode Strings Using Base64 | base64.js

jQuery Base64 JS is a jQuery plugin that helps create a Base64 decoder and encoder online application for client-side encryption and decryption of Base64 data.

How to make use of it:

1. Create Textarea components for the Base64 decoder and encoder.

<form>
  <label for="encode" class="encode">Encode</label>
  <textarea id="encode">AddCode</textarea>
  <label for="decode" class="decode">Decode</label>
  <textarea id="decode">alF1ZXJ5U2NyaXB0</textarea>
</form>

2. Place jQuery JavaScript library and the jquery.base64.js script on the bottom of the webpage.

<script src="/path/to/cdn/jquery.min.js"></script>
<script src="/path/to/jquery.base64.js"></script>

3. The essential JavaScript to activate the Base64 decoder and encoder.

var dec = $('#decode'),
    enc = $('#encode');

enc.keyup(function () {
    dec.val($.base64.btoa(this.value));
    // also possible:
    // dec.val( $.base64('encode', this.value) );
    // dec.val( $.base64.encode(this.value) );
});

dec.keyup(function () {
    // note: you can pass a third parameter to use the utf8 en- / decode option
    enc.val($.base64.atob(this.value, true));
    // also possible:
    // dec.val( $.base64('decode', this.value) );
    // dec.val( $.base64.decode(this.value) );
});

$('textarea').on('focus blur', function () {
    $(this).prev('label').stop().fadeToggle(200);
});

4. You can set utf8 encoding and decoding by way of global choices:

$.base64.utf8encode = true;

Base64 Decoder and Encoder In jQuery, jQuery Base64 Plugin/Github


See Demo And Download

Official Website(yckart): Click Here

This superior jQuery/javascript plugin is developed by yckart. For extra Advanced Usage, please go to the official website.

Share