![](/img/trans.png)
[英]How to fix "TypeError: Cannot read properties of undefined (reading 'useSystemColorMode')"
[英]How to fix TypeError: Cannot read properties of undefined (reading 'words')?
我已经在我的本地存储加密和解密应用程序中实现了 crypto-Js。 它工作正常。
问题::刷新时,页面变黑,控制台抛出以下错误:
TypeError: Cannot read properties of undefined (reading 'words')
at Object._doReset (aes.js:103:1)
at Object.reset (cipher-core.js:119:1)
at Object.reset (cipher-core.js:461:1)
at Object.init (cipher-core.js:104:1)
at subtype.init (core.js:149:1)
at subtype.init (core.js:149:1)
at subtype.init (core.js:149:1)
at Object.create (core.js:176:1)
at Object.createDecryptor (cipher-core.js:81:1)
at Object.decrypt (cipher-core.js:728:1)
注意:如果我清除本地存储并再次尝试它会起作用。但是每当我刷新页面时都会发生此错误并且页面变为空白。
我想向您展示我使用过的加密和解密function如下:
................... imports .............
import * as CryptoJs from 'crypto-js';
let key: string;
const SECURE_DATA = {
encrypt: (state: string) => CryptoJs.AES.encrypt(state, key).toString(),
decrypt: (state: string) => CryptoJs.AES.decrypt(state, key).toString(CryptoJs.enc.Utf8),
};
const STORE_KEYS_TO_PERSIST = [
{ auth: SECURE_DATA },
...
];
export interface StoreState {
auth: User;
....
}
export const reducers: ActionReducerMap<StoreState> = {
auth: authReducer,
....
};
export function localStorageSyncReducer(
reducer: ActionReducer<StoreState>
): ActionReducer<StoreState> {
return localStorageSync({
keys: STORE_KEYS_TO_PERSIST,
rehydrate: true,
syncCondition(state) {
key = state.auth.token;
return true;
},
})(reducer);
}
export function clearState(reducer) {
return function (state, action) {
if (action.type === ActionTypes.LOG_OUT) {
state = undefined;
}
return reducer(state, action);
};
}
export const metaReducers: Array<MetaReducer<StoreState, Action>> = [
localStorageSyncReducer,
clearState,
];
我认为将字符串转换为 CryptoJS wordArray 会生成它正在搜索的单词。
const encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(key), 'phrase');
另外,比较价值。 你得到什么? 它是未定义的还是一个值? 从这里,您将了解缺少哪个值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.