From 52ceb5b53faf5abeffbf09df0e30557ded0faebe Mon Sep 17 00:00:00 2001 From: Liu Xin Date: Wed, 3 Aug 2022 08:05:38 +0800 Subject: [PATCH] fix: Replace atob for encod encryption in login (#3490) Signed-off-by: harrisonliu5 --- src/core/containers/Login/index.jsx | 6 +++--- src/utils/index.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/containers/Login/index.jsx b/src/core/containers/Login/index.jsx index c891e7eed19..6e2f71771ef 100644 --- a/src/core/containers/Login/index.jsx +++ b/src/core/containers/Login/index.jsx @@ -30,10 +30,11 @@ import { import { get } from 'lodash' +import { Base64 } from 'js-base64' import styles from './index.scss' function encrypt(salt, str) { - return mix(salt, window.btoa(str)) + return mix(salt, Base64.encode(str)) } function mix(salt, str) { @@ -49,8 +50,7 @@ function mix(salt, str) { prefix.push(sum % 2 === 0 ? '0' : '1') ret.push(String.fromCharCode(Math.floor(sum / 2))) } - - return `${window.btoa(prefix.join(''))}@${ret.join('')}` + return `${Base64.encode(prefix.join(''))}@${ret.join('')}` } @inject('rootStore') diff --git a/src/utils/index.js b/src/utils/index.js index 309cd469ecb..fb16ec643e9 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -37,8 +37,8 @@ import { import generate from 'nanoid/generate' import moment from 'moment-mini' +import { Base64 } from 'js-base64' import { PATTERN_LABEL, MODULE_KIND_MAP } from './constants' - /** * format size, output the value with unit * @param {Number} size - the number need to be format @@ -748,7 +748,7 @@ export const inCluster2Default = name => { } export const encrypt = (salt, str) => { - return mix(salt, window.btoa(str)) + return mix(salt, Base64.encode(str)) } function mix(salt, str) { @@ -765,5 +765,5 @@ function mix(salt, str) { ret.push(String.fromCharCode(Math.floor(sum / 2))) } - return `${window.btoa(prefix.join(''))}@${ret.join('')}` + return `${Base64.encode(prefix.join(''))}@${ret.join('')}` }