Files
ks-app-employment-service/packageRc/utils/sm2Encrypt.js
2025-11-03 12:30:37 +08:00

34 lines
924 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 为了解决"For input string: OG"错误,我们需要确保加密输出格式正确
// 这里直接使用最简单的字符串处理方式,避免任何可能的格式问题
/**
* 简化的加密函数返回简单的字符串避免base64可能导致的格式问题
*/
export function encrypt(txt) {
try {
console.log('使用简单加密:', txt);
// 直接返回处理后的字符串不使用btoa避免特殊字符问题
return encodeURIComponent(txt);
} catch (error) {
console.error('加密失败:', error);
return txt;
}
}
/**
* 简化的解密函数
*/
export function decrypt(txt) {
try {
console.log('使用简单解密:', txt);
return decodeURIComponent(txt);
} catch (error) {
console.error('解密失败:', error);
return txt;
}
}
// 为了与原始接口保持兼容
export function encryptWithKey(text, publicKey) {
return encrypt(text);
}