两种方法,一种是下载包

npm i --save js-base64

然后再组件中引用

const Base64 = require("js-base64").Base64

进行加密

let content = Base64.encode(this.form.content)

方法二,自己封装js文件

//
// THIS FILE IS AUTOMATICALLY GENERATED! DO NOT EDIT BY HAND!
//
;(function(global, factory) {typeof exports === 'object' && typeof module !== 'undefined'? module.exports = factory(): typeof define === 'function' && define.amd? define(factory) :// cf. https://github.com/dankogai/js-base64/issues/119(function() {// existing version for noConflict()const _Base64 = global.Base64;const gBase64 = factory();gBase64.noConflict = () => {global.Base64 = _Base64;return gBase64;};if (global.Meteor) { // Meteor.jsBase64 = gBase64;}global.Base64 = gBase64;})();
}((typeof self !== 'undefined' ? self: typeof window !== 'undefined' ? window: typeof global !== 'undefined' ? global: this
), function() {'use strict';/***  base64.ts**  Licensed under the BSD 3-Clause License.*    http://opensource.org/licenses/BSD-3-Clause**  References:*    http://en.wikipedia.org/wiki/Base64** @author Dan Kogai (https://github.com/dankogai)*/
const version = '3.4.5';
/*** @deprecated use lowercase `version`.*/
const VERSION = version;
const _hasatob = typeof atob === 'function';
const _hasbtoa = typeof btoa === 'function';
const _hasBuffer = typeof Buffer === 'function';
const b64ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
const b64chs = [...b64ch];
const b64tab = ((a) => {let tab = {};a.forEach((c, i) => tab[c] = i);return tab;
})(b64chs);
const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
const _fromCC = String.fromCharCode.bind(String);
const _U8Afrom = typeof Uint8Array.from === 'function'? Uint8Array.from.bind(Uint8Array): (it, fn = (x) => x) => new Uint8Array(Array.prototype.slice.call(it, 0).map(fn));
const _mkUriSafe = (src) => src.replace(/[+\/]/g, (m0) => m0 == '+' ? '-' : '_').replace(/=+$/m, '');
const _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\+\/]/g, '');
/*** polyfill version of `btoa`*/
const btoaPolyfill = (bin) => {// console.log('polyfilled');let u32, c0, c1, c2, asc = '';const pad = bin.length % 3;for (let i = 0; i < bin.length;) {if ((c0 = bin.charCodeAt(i++)) > 255 ||(c1 = bin.charCodeAt(i++)) > 255 ||(c2 = bin.charCodeAt(i++)) > 255)throw new TypeError('invalid character found');u32 = (c0 << 16) | (c1 << 8) | c2;asc += b64chs[u32 >> 18 & 63]+ b64chs[u32 >> 12 & 63]+ b64chs[u32 >> 6 & 63]+ b64chs[u32 & 63];}return pad ? asc.slice(0, pad - 3) + "===".substring(pad) : asc;
};
/*** does what `window.btoa` of web browsers do.* @param {String} bin binary string* @returns {string} Base64-encoded string*/
const _btoa = _hasbtoa ? (bin) => btoa(bin): _hasBuffer ? (bin) => Buffer.from(bin, 'binary').toString('base64'): btoaPolyfill;
const _fromUint8Array = _hasBuffer? (u8a) => Buffer.from(u8a).toString('base64'): (u8a) => {// cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326const maxargs = 0x1000;let strs = [];for (let i = 0, l = u8a.length; i < l; i += maxargs) {strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));}return _btoa(strs.join(''));};
/*** converts a Uint8Array to a Base64 string.* @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5* @returns {string} Base64 string*/
const fromUint8Array = (u8a, urlsafe = false) => urlsafe ? _mkUriSafe(_fromUint8Array(u8a)) : _fromUint8Array(u8a);
/*** @deprecated should have been internal use only.* @param {string} src UTF-8 string* @returns {string} UTF-16 string*/
const utob = (src) => unescape(encodeURIComponent(src));
//
const _encode = _hasBuffer? (s) => Buffer.from(s, 'utf8').toString('base64'): (s) => _btoa(utob(s));
/*** converts a UTF-8-encoded string to a Base64 string.* @param {boolean} [urlsafe] if `true` make the result URL-safe* @returns {string} Base64 string*/
const encode = (src, urlsafe = false) => urlsafe? _mkUriSafe(_encode(src)): _encode(src);
/*** converts a UTF-8-encoded string to URL-safe Base64 RFC4648 §5.* @returns {string} Base64 string*/
const encodeURI = (src) => encode(src, true);
/*** @deprecated should have been internal use only.* @param {string} src UTF-16 string* @returns {string} UTF-8 string*/
const btou = (src) => decodeURIComponent(escape(src));
/*** polyfill version of `atob`*/
const atobPolyfill = (asc) => {// console.log('polyfilled');asc = asc.replace(/\s+/g, '');if (!b64re.test(asc))throw new TypeError('malformed base64.');asc += '=='.slice(2 - (asc.length & 3));let u24, bin = '', r1, r2;for (let i = 0; i < asc.length;) {u24 = b64tab[asc.charAt(i++)] << 18| b64tab[asc.charAt(i++)] << 12| (r1 = b64tab[asc.charAt(i++)]) << 6| (r2 = b64tab[asc.charAt(i++)]);bin += r1 === 64 ? _fromCC(u24 >> 16 & 255): r2 === 64 ? _fromCC(u24 >> 16 & 255, u24 >> 8 & 255): _fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255);}return bin;
};
/*** does what `window.atob` of web browsers do.* @param {String} asc Base64-encoded string* @returns {string} binary string*/
const _atob = _hasatob ? (asc) => atob(_tidyB64(asc)): _hasBuffer ? (asc) => Buffer.from(asc, 'base64').toString('binary'): atobPolyfill;
const _decode = _hasBuffer? (a) => Buffer.from(a, 'base64').toString('utf8'): (a) => btou(_atob(a));
const _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == '-' ? '+' : '/'));
/*** converts a Base64 string to a UTF-8 string.* @param {String} src Base64 string.  Both normal and URL-safe are supported* @returns {string} UTF-8 string*/
const decode = (src) => _decode(_unURI(src));
/*** converts a Base64 string to a Uint8Array.*/
const toUint8Array = _hasBuffer? (a) => _U8Afrom(Buffer.from(_unURI(a), 'base64')): (a) => _U8Afrom(_atob(_unURI(a)), c => c.charCodeAt(0));
const _noEnum = (v) => {return {value: v, enumerable: false, writable: true, configurable: true};
};
/*** extend String.prototype with relevant methods*/
const extendString = function () {const _add = (name, body) => Object.defineProperty(String.prototype, name, _noEnum(body));_add('fromBase64', function () { return decode(this); });_add('toBase64', function (urlsafe) { return encode(this, urlsafe); });_add('toBase64URI', function () { return encode(this, true); });_add('toBase64URL', function () { return encode(this, true); });_add('toUint8Array', function () { return toUint8Array(this); });
};
/*** extend Uint8Array.prototype with relevant methods*/
const extendUint8Array = function () {const _add = (name, body) => Object.defineProperty(Uint8Array.prototype, name, _noEnum(body));_add('toBase64', function (urlsafe) { return fromUint8Array(this, urlsafe); });_add('toBase64URI', function () { return fromUint8Array(this, true); });_add('toBase64URL', function () { return fromUint8Array(this, true); });
};
/*** extend Builtin prototypes with relevant methods*/
const extendBuiltins = () => {extendString();extendUint8Array();
};
const gBase64 = {version: version,VERSION: VERSION,atob: _atob,atobPolyfill: atobPolyfill,btoa: _btoa,btoaPolyfill: btoaPolyfill,fromBase64: decode,toBase64: encode,encode: encode,encodeURI: encodeURI,encodeURL: encodeURI,utob: utob,btou: btou,decode: decode,fromUint8Array: fromUint8Array,toUint8Array: toUint8Array,extendString: extendString,extendUint8Array: extendUint8Array,extendBuiltins: extendBuiltins,
};//// export Base64 to the namespace//// ES5 is yet to have Object.assign() that may make transpilers unhappy.// gBase64.Base64 = Object.assign({}, gBase64);gBase64.Base64 = {};Object.keys(gBase64).forEach(k => gBase64.Base64[k] = gBase64[k]);return gBase64;
}));

然后引入并加密

vue中给字段base 64加密相关推荐

  1. vue中使用js进行AES加密及解密(含密钥和iv偏移量)、以及HMAC-SHA256加密方法对于签名加密的使用

    一.AES加密解密 1.下载安装 npm install crypto-js --save-dev 2.在utils文件夹下创建encryp.js文件进行aes加密解密工具类方法的封装 import ...

  2. Java 密码系列 - Java 和 JS Base 64

    Base 64 不属于密码技术,仅是编码方式.但由于在 Java.JavaScript.区块链等出现的频率较高,故在本系列文章中首先分享 Base 64 编码技术.前面部分主要介绍 Base 64 理 ...

  3. 十分钟快速掌握 Base 64 | Java JS 密码系列

    Java 密码系列 - Java 和 JS Base 64 Base 64 不属于密码技术,仅是编码方式.但由于在 Java.JavaScript.区块链等出现的频率较高,故在本系列文章中首先分享 B ...

  4. 天蓝色在ps中的色值_天蓝色的cosmosdb文档中的字段级加密

    天蓝色在ps中的色值 In today's world customer's data security and privacy is of utmost importance. This becom ...

  5. vue中使用MD5加密

    在vue中使用MD5加密  安装:  使用npm npm install --save blueimp-md5 <script src="http://cdn.bootcss.com/ ...

  6. Vue中前端加密使用RSA加密下的JSEncrypt防止明文暴露

    场景 前端使用Vue在进行登录时,需要将密码存进cookie中. 为了防止密码明文暴露,前端需要采用加密方式对密码进行加密. 常用加密方式之一就是RSA加密解密. RSA加密是一种非对称加密.可以在不 ...

  7. vue中 使用md5加密

    安装 npm install js-md5 --save 组件内引入 需要的组件内引用 import md5 from 'js-md5'; 使用 let psd = '123123' md5(psd) ...

  8. MySQL中AES_ENCRYPT('密码','钥匙')函数 可以对字段值做加密处理

    MySQL中AES_ENCRYPT('密码','钥匙')函数 可以对字段值做加密处理        AES_DECRYPT(表的字段名字,'钥匙')函数 解密处理 例,表结构: 现在插入一条数据,对p ...

  9. SpringBoot+Vue中使用AES进行加解密(加密模式等对照关系)

    场景 若依前后端分离版本地搭建开发环境并运行项目的教程: 若依前后端分离版手把手教你本地搭建环境并运行项目_霸道流氓气质的博客-CSDN博客 在上面搭建起来前后端架构之后,在前后端分别进行AES方式的 ...

最新文章

  1. java 嵌套类 继承_Java嵌套类 - 爱吃苹果的搬运工的个人空间 - OSCHINA - 中文开源技术交流社区...
  2. Linux 在 linux 中搭建 FTP 服务
  3. [html] 表单可以跨域吗?
  4. 入选 SIGMOD2021 的时间序列多周期检测通用框架 RobustPeriod 如何支撑阿里业务场景?
  5. python 静态方法_Python编程思想(25):方法深度解析
  6. 直方图均衡化计算过程步骤
  7. java io教程_Java IO教程
  8. 创业型 APP 如何筛选合适的推送平台
  9. UL/OL与LI 标签结合CSS的运用
  10. 全国各地将推广电子证照,取代一证通
  11. 如何查找计算机密码cmd,教你如何查看计算机所连wifi密码
  12. 我的世界基岩版json_我的世界 基岩版:官方服务器配置与使用
  13. 强强联合,怿星科技艾拉比携手斩获“铃轩奖”
  14. 前端React 框架- UmiJS有听说过吗?
  15. L1-057 PTA使我精神焕发 (5分)(C语言)
  16. ISO/IEC27040认证标准的概述和简介
  17. 钢绞线弹性模量怎么计算_预应力钢绞线参数及计算公式汇总
  18. 适合Python初学者阅读的Github开源代码
  19. 桂电信科17级c语言期末试卷,桂电期末考试Linux习题总结
  20. 学术会议论文查重吗_学术论文会论文查重吗?

热门文章

  1. 氧化锌@聚丙烯腈(ZnO@PAN)静电纺丝纳米纤维膜材料|金属有机框架材料ZIF-8@聚丙烯腈(ZIF-8@PAN)纳米纤维膜材料
  2. VMware Fusion for mac虚拟机中Linux系统并使用ssh连接
  3. python数据类型(下)
  4. 超全面!如何系统学习功能图标
  5. 大学常用计算机软件推荐+安装教程
  6. DSP(f2812/28335/28377/28388)TZ功能说明
  7. IBL-镜面反射(预滤波篇)
  8. js 遍历对象的方式
  9. Shell脚本攻略04-玩转文件描述符及重定向
  10. java中遍历一个对象的所有属性