I am trying to encrypt and correspondingly decrypt a string.
When I am specifying the encoding scheme as 'utf-8', I am getting the results as expected :
    function encrypt(text) {
        var cipher = crypto.createCipher(algorithm, password)
        var crypted = cipher.update(text, 'utf8', 'hex')
        crypted += cipher.final('hex');
        return crypted;
    }
    function decrypt(text) {
        var decipher = crypto.createDecipher(algorithm, password)
        var dec = decipher.update(text, 'hex', 'utf8')
        dec += decipher.final('utf8');
        return dec;
    }
//text = 'The big brown fox jumps over the lazy dog.'  
Output : (utf-8 encoding)
But when I am trying to do it with 'base-64', its giving me unexpected results :
function encrypt(text) {
    var cipher = crypto.createCipher(algorithm, password)
    var crypted = cipher.update(text, 'base64', 'hex')
    crypted += cipher.final('hex');
    return crypted;
}
function decrypt(text) {
    var decipher = crypto.createDecipher(algorithm, password)
    var dec = decipher.update(text, 'hex', 'base64')
    dec += decipher.final('base64');
    return dec;
}
Output : (base-64 encoding)
I am unable to understand why base-64 encoding scheme is not accepting up the spaces and '.' in right format.
If someone know this, please help me out in getting a better understanding for this.
Any help is appreciated.


 
     
    