if ( typeof String.prototype.base64Encode == 'undefined' ) {
String.prototype.base64Encode = function () {
if ( typeof btoa != 'undefined' ) return btoa( this ); // browser
if ( typeof Buffer != 'undefined' ) return new Buffer( this , 'utf8' ).toString( 'base64' ); // Node.js
throw new Error( 'No Base64 Encode' );
};
}
if ( typeof String.prototype.base64Decode == 'undefined' ) {
String.prototype.base64Decode = function () {
if ( typeof atob != 'undefined' ) return atob( this ); // browser
if ( typeof Buffer != 'undefined' ) return new Buffer( this , 'base64' ).toString( 'utf8' ); // Node.js
throw new Error( 'No Base64 Decode' );
};
}
|
btoa 在开发者工具中未定义,但是atob居然定义了,导致加密库不能用。