HarmonyOS base64.decodeSync(str)使用报错

word:oMXKoLLGploX7RNypkcEfIzvHI6TtX35FQ1IIpNiMdJvisN1MULSXOdvtfM7fVsQEqPh_VNaur8z8Oh1ROh9SfOi7FGwgQ3GH9b9l_NERPCmyVI2BBRsQZzZD5Y74upT4yBLMVfKJ-14ExiQY0F7xrKOTERO6d-Bop9_wcVH1SPOAQnJOcAjYJebd_N5crBtlz3UZmXeqmsocrwuFkXuYFHX9mjkcRhi2BwrektP9g6UKp_big7yi9kTVyB8SLQ4tauPEaGN_q0leHvn01q3xF_IXJhkjvV-XIedyyB2gmBFJBrhRRQZweoSBl142HPvZeTONl0qSgawefxZ6w36mmDPOHZbRhxXvdOGgKs6ri60YBEa9mqK-BwshqlQqlkCCWWMweuGIdqWlqIFk14EIrCbfsfNmF8fkPvbZkk2B0hyHD_SKFTpHTigYBRPHPI-UAX3u-K7UZ5XU3O4UnkQYA

/**
 * base64 解码器 解密
 * '-' -> '+'
 * '_' -> '/'
 */
public static decode(word: string): Uint8Array {
  const data = word.replace("-", "+").replace("_", "/")
  const mod = data.length % 4
  const str = (mod > 0) ? data + "====".substring(mod) : data
  const base64 = new util.Base64Helper();
  return base64.decodeSync(str); // base64转Uint8Array
}

报错:TypeError: Cannot read property decodeSync of undefined

想问一下怎么改

HarmonyOS
1天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
Heiang

以下为输出

replaceAll      oMXKoLLGploX7RNypkcEfIzvHI6TtX35FQ1IIpNiMdJvisN1MULSXOdvtfM7fVsQEqPh/VNaur8z8Oh1ROh9SfOi7FGwgQ3GH9b9l/NERPCmyVI2BBRsQZzZD5Y74upT4yBLMVfKJ+14ExiQY0F7xrKOTERO6d+Bop9/wcVH1SPOAQnJOcAjYJebd/N5crBtlz3UZmXeqmsocrwuFkXuYFHX9mjkcRhi2BwrektP9g6UKp/big7yi9kTVyB8SLQ4tauPEaGN/q0leHvn01q3xF/IXJhkjvV+XIedyyB2gmBFJBrhRRQZweoSBl142HPvZeTONl0qSgawefxZ6w36mmDPOHZbRhxXvdOGgKs6ri60YBEa9mqK+BwshqlQqlkCCWWMweuGIdqWlqIFk14EIrCbfsfNmF8fkPvbZkk2B0hyHD/SKFTpHTigYBRPHPI+UAX3u+K7UZ5XU3O4UnkQYA

mod ok      2

string mod      oMXKoLLGploX7RNypkcEfIzvHI6TtX35FQ1IIpNiMdJvisN1MULSXOdvtfM7fVsQEqPh/VNaur8z8Oh1ROh9SfOi7FGwgQ3GH9b9l/NERPCmyVI2BBRsQZzZD5Y74upT4yBLMVfKJ+14ExiQY0F7xrKOTERO6d+Bop9/wcVH1SPOAQnJOcAjYJebd/N5crBtlz3UZmXeqmsocrwuFkXuYFHX9mjkcRhi2BwrektP9g6UKp/big7yi9kTVyB8SLQ4tauPEaGN/q0leHvn01q3xF/IXJhkjvV+XIedyyB2gmBFJBrhRRQZweoSBl142HPvZeTONl0qSgawefxZ6w36mmDPOHZbRhxXvdOGgKs6ri60YBEa9mqK+BwshqlQqlkCCWWMweuGIdqWlqIFk14EIrCbfsfNmF8fkPvbZkk2B0hyHD/SKFTpHTigYBRPHPI+UAX3u+K7UZ5XU3O4UnkQYA==

decodeSync      160,197,202,160,178,198,166,90,23,237,19,114,166,71,4,124,140,239,28,142,147,181,125,249,21,13,72,34,147,98,49,210,111,138,195,117,49,66,210,92,231,111,181,243,59,125,91,16,18,163,225,253,83,90,186,191,51,240,232,117,68,232,125,73,243,162,236,81,176,129,13,198,31,214,253,151,243,68,68,240,166,201,82,54,4,20,108,65,156,217,15,150,59,226,234,83,227,32,75,49,87,202,39,237,120,19,24,144,99,65,123,198,178,142,76,68,78,233,223,129,162,159,127,193,197,71,213,35,206,1,9,201,57,192,35,96,151,155,119,243,121,114,176,109,151,61,212,102,101,222,170,107,40,114,188,46,22,69,238,96,81,215,246,104,228,113,24,98,216,28,43,122,75,79,246,14,148,42,159,219,138,14,242,139,217,19,87,32,124,72,180,56,181,171,143,17,161,141,254,173,37,120,123,231,211,90,183,196,95,200,92,152,100,142,245,126,92,135,157,203,32,118,130,96,69,36,26,225,69,20,25,193,234,18,6,93,120,216,115,239,101,228,206,54,93,42,74,6,176,121,252,89,235,13,250,154,96,207,56,118,91,70,28,87,189,211,134,128,171,58,174,46,180,96,17,26,246,106,138,248,28,44,134,169,80,170,89,2,9,101,140,193,235,134,33,218,150,150,162,5,147,94,4,34,176,155,126,199,205,152,95,31,144,251,219,102,73,54,7,72,114,28,63,210,40,84,233,29,56,160,96,20,79,28,242,62,80,5,247,187,226,187,81,158,87,83,115,184,82,121,16,96
let base64 = new util.Base64Helper()
let string = "oMXKoLLGploX7RNypkcEfIzvHI6TtX35FQ1IIpNiMdJvisN1MULSXOdvtfM7fVsQEqPh_VNaur8z8Oh1ROh9SfOi7FGwgQ3GH9b9l_NERPCmyVI2BBRsQZzZD5Y74upT4yBLMVfKJ-14ExiQY0F7xrKOTERO6d-Bop9_wcVH1SPOAQnJOcAjYJebd_N5crBtlz3UZmXeqmsocrwuFkXuYFHX9mjkcRhi2BwrektP9g6UKp_big7yi9kTVyB8SLQ4tauPEaGN_q0leHvn01q3xF_IXJhkjvV-XIedyyB2gmBFJBrhRRQZweoSBl142HPvZeTONl0qSgawefxZ6w36mmDPOHZbRhxXvdOGgKs6ri60YBEa9mqK-BwshqlQqlkCCWWMweuGIdqWlqIFk14EIrCbfsfNmF8fkPvbZkk2B0hyHD_SKFTpHTigYBRPHPI-UAX3u-K7UZ5XU3O4UnkQYA"

let string2= string.replaceAll("-","+")
let string3= string2.replaceAll("_","/")
console.info('replaceAll      '+ string3) ;
let mod = string3.length%4
console.info('mod ok      '+ mod) ;
string = (mod > 0) ? string3 +"====".substring(mod):string
console.info('string mod'+ string) ;
console.info('decodeSync'+ base64.decodeSync(string)) ;
分享
微博
QQ
微信
回复
1天前
相关问题
Base64Helper.decodeSync 报错
234浏览 • 1回复 待解决
HarmonyOS Base64Helper().decodeSync报错
182浏览 • 1回复 待解决
HarmonyOS base64解码报错
1064浏览 • 1回复 待解决
HarmonyOS 图片进行base64编码报错
735浏览 • 1回复 待解决
HarmonyOS react-native-svg(CAPI)使用报错
46浏览 • 1回复 待解决
HarmonyOS react-native-device-info使用报错
38浏览 • 1回复 待解决
HarmonyOS 关于Image组件使用base64图片
268浏览 • 1回复 待解决
HarmonyOS base64编码问题
672浏览 • 1回复 待解决
HarmonyOS base64转image
84浏览 • 1回复 待解决
HarmonyOS 图片转base64
109浏览 • 1回复 待解决
HarmonyOS base64编码的API
214浏览 • 1回复 待解决
HarmonyOS arraybuffer转base64乱码
185浏览 • 1回复 待解决
HarmonyOS base64编解码
43浏览 • 0回复 待解决
HarmonyOS 图片Base64编码
75浏览 • 1回复 待解决
HarmonyOS string怎么base64和decodeBase64
70浏览 • 1回复 待解决
HarmonyOS 中文base64加密解密乱码
601浏览 • 1回复 待解决
HarmonyOS Image加载base64失败
37浏览 • 1回复 待解决
har 包引用报错的问题
426浏览 • 1回复 待解决
HarmonyOS如何将图片转Base64
934浏览 • 1回复 待解决
HarmonyOS 图片操作,合成后导出base64
235浏览 • 1回复 待解决
HarmonyOS 加解密base64转换
31浏览 • 1回复 待解决
怎么把PixelMap图片转BASE64
9458浏览 • 1回复 待解决