Base64Helper.decodeSync 报错

Base64Helper.decodeSync 报错不支持的字符, 看下这个字符串能怎么处理。

MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCS_lmg9K_SgIXPioI008uwpxFuKp-2o7orhjXC5uoW_8AX8e7Ygco8927XtDgEVM0od90trIeh_3ROCFdLFUqViuE5lINhCzb7lIivrYf2dR49_4rlJ9w8ZAkStDSd0NbPbNePsrjCJE4UKhySgwBlnX6IGd82xl5lp67Zah7TFn8bVFITCNkq13-9bR3Z45ZPzFsnoh7lV3825xfdE1qJxlldGWcTMZmNfgOHDDS9NbZavthUZxt_AT1KdQKlqXq39ngJT9kes0HcVuPL63OSoV1j5GVTpKp6xQiFCAh_VAjtibmbENXUPp2CeoMPIODSU5dZXdVWkaCtA0cnkWXxAgMBAAECggEBAIpPG0SQl1NJLR8AI83TL0hzmrn_DzKJ0eWcLb_LCJ5FXJjrQqKjVQiShNAfucmRhUy7o_iS6zgppmS6AnEagog9GfjU3d2U8NI9i3NJo7Hpt1_8r9M480g7lDHuL8gCteyMbDPApYm_IVxl12agLuJuE526QkZG1pFt-t6FtKVGgbRAcp7b2GHQ9WBPy9w1SN4iDVEGKCqXwrCLv_fbhYeMYcdkGTWDwxlPpkjjE-kPjVSABKLHUDFlX6Xlwnz0E9CnDMvmuiOlXx5UFVYk3TYgumYC1UCKjqsazhFXb3j5riQiSXH2yxzOUp2hKwrse1ZWP6MRfJJnYY-yF0wHdiUCgYEA9LshaHsccKyG1v3d7PCxuOegO-RFtQGhpI3wqJ_6TWe8GI88DkYdc3uSyjt4n1TNGbjWeDyJ_uugB4y4GBrLRm8NLlVAtPHfWvoMs5y_E28F0BtO7VnrDWyOMVfVFlHRXghZwOTUUljXgeP5l-ZkAF7OiWkt7fqvND_fIsK0dPcCgYEAmcMZO2eyuPvACKmePllkQlkYNbfUDcpSAIDkEPonSgnu0JQeSBWyO-CYqlMsE3ZZ-v_Ih2d-PyRZwxOdCiYTj0-Yf6GNzFMOc3IIi_KAxfhqgirAH7Scvkw10Hzpz3lXJbRimbI-7v-RI8O33ER3p3gRO52PXj6t2ow4cV60ClcCgYEAt_W-PBpmm2-kgBEec8_N1-8MrFh_6XrLdbVYVHjEntC-PDvW6efclYUrJycjGamV7qLZXFItbNjTVzl43G2vpUcuwkhFNn6l5W4WhCDsJICM_wy3_IRdwp56GC8stvVTivp99RhNXYT4oeOrJ3qAayLY38OXSc7pSj5EzY1MNqsCgYAC3ynxehZUbh9ACirybyj4NEHHfw9u0oCFkeKwjnt9XoIfUyTdo8oYZDF1vOft1SAJGA3euYgaFcu3YP5l2iAzZQEsIRBM6KA0d8TBGF5fVCxpEfNUpELpKvM2WZ7kSRfflGbjB_k07YEAcf9VFdJGRm_L9T1gPTtyAXxsYaBrMQKBgG0kzf2cdWUqgBWrX33Gvi4O2QPGnmz-GHEZ4fQiSZBDHSISN3qUoVNfFKPszTqYQqinIMzEQaqxc110KfYGVDl_X82JciVDTAVR9otygXw6-AlgDjy_15Ma7GwqtbdEEiHEfThN6BiZ2sizuJ0geGEIeuayPvc8o-r8BxYyZomX
HarmonyOS
2024-11-08 10:59:43
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
Heiang

​Base64编码表包含A-Z、a-z、0-9这62个字符,以及"+“和”/"这两个特殊字符,下划线是非法字符,参考链接如下​https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-util-V5

参考一下:​

import util from '@ohos.util'; 
@Entry 
@Component 
struct Index { 
  @State message: string = 'Hello World!' 
  str: string = 'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCS_lmg9K_SgIXPioI008uwpxFuKp-2o7orhjXC5uoW_8AX8e7Ygco8927XtDgEVM0od90trIeh_3ROCFdLFUqViuE5lINhCzb7lIivrYf2dR49_4rlJ9w8ZAkStDSd0NbPbNePsrjCJE4UKhySgwBlnX6IGd82xl5lp67Zah7TFn8bVFITCNkq13-9bR3Z45ZPzFsnoh7lV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YZDF1vOft1SAJGA3euYgaFcu3YP5l2iAzZQEsIRBM6KA0d8TBGF5fVCxpEfNUpELpKvM2WZ7kSRfflGbjB_k07YEAcf9VFdJGRm_L9T1gPTtyAXxsYaBrMQKBgG0kzf2cdWUqgBWrX33Gvi4O2QPGnmz-GHEZ4fQiSZBDHSISN3qUoVNfFKPszTqYQqinIMzEQaqxc110KfYGVDl_X82JciVDTAVR9otygXw6-AlgDjy_15Ma7GwqtbdEEiHEfThN6BiZ2sizuJ0geGEIeuayPvc8o-r8BxYyZomX' 
  getBase64Str(str: string): string{ 
    return str.replace(/[^A-Za-z0-9+\/=]/g,'') 
  }_x000D_ 
  /******/_x000D_ 
  build() { 
    Row() { 
      Column() { 
        Button(this.message) 
          .onClick(()=>{ 
            let base64 = new util.Base64Helper(); 
            base64.decodeSync(this.getBase64Str(this.str)) 
          }) 
          .fontSize(50) 
          .fontWeight(FontWeight.Bold) 
 
      } 
      .width('100%') 
    } 
    .height('100%') 
  } 
}
分享
微博
QQ
微信
回复
2024-11-08 16:56:41
相关问题
HarmonyOS base64解码报错
692浏览 • 1回复 待解决
HarmonyOS 图片进行base64编码报错
530浏览 • 1回复 待解决
HarmonyOS base64编码问题
433浏览 • 1回复 待解决
HarmonyOS base64编码的API
104浏览 • 1回复 待解决
HarmonyOS arraybuffer转base64乱码
32浏览 • 1回复 待解决
arkts中怎么实现base64编码?
705浏览 • 1回复 待解决
PixelMap怎么转Base64?(非Java)
3131浏览 • 2回复 待解决
怎么把PixelMap图片转BASE64
9246浏览 • 1回复 待解决
HarmonyOS 中文base64加密解密乱码
450浏览 • 1回复 待解决
HarmonyOS 图片压缩和图片转base64
42浏览 • 1回复 待解决
HarmonyOS Image如何显示base64的图片?
322浏览 • 1回复 待解决
js canvas转base64编码图片不全
10624浏览 • 1回复 待解决
HarmonyOS 图片操作,合成后导出base64
86浏览 • 1回复 待解决
如何base64转换成图片?
10159浏览 • 2回复 待解决
HarmonyOS如何将图片转Base64
788浏览 • 1回复 待解决
验证pixelmap数据buffer转base64是否正常
1745浏览 • 1回复 待解决
有没有base64转化的相关代码?
710浏览 • 0回复 待解决
如何进行base64编码,有人知道吗?
579浏览 • 1回复 待解决
HarmonyOS 图片转为base64字符串
90浏览 • 1回复 待解决
如何实现PixelMap和base64的相互转换
1645浏览 • 1回复 待解决
HarmonyOS 如何将base64数据转换为图片
386浏览 • 1回复 待解决