我有一个字符串:
'MIIciwYJKoZIhvcNAQcCoIIcfDCCHHgCAQExCzAJBgUrDgMCGgUAMIIMLAYJKoZIhvcNAQcBoIIMHQSCDBkxggwVMAoCAQgCAQEEAhYAMAoCARQCAQEEAgwAMAsCAQECAQEEAwIBADALAgEDAgEBBAMMATEwCwIBCwIBAQQDAgEAMAsCAQ4CAQEEAwIBajALAgEPAgEBBAMCAQAwCwIBEAIBAQQDAgEAMAsCARkCAQEEAwIBAzAMAgEKAgEBBAQWAjQrMA0CAQ0CAQEEBQIDAYahMA0CARMCAQEEBQwDMS4wMA4CAQkCAQEEBgIEUDI0NzAYAgEEAgECBBDTMQqCVP9JNijerDz8F4JOMBsCAQACAQEEEwwRUHJvZHVjdGlvblNhbmRib3gwGwIBAgIBAQQTDBFwb3RhdG9sYWJzLmJhbmFuYTAcAgEFAgEBBBSwSAEz57UFwfMJ0Yf7USotU0nrhDAeAgEMAgEBBBYWFDIwMTYtMTItMjBUMTg6MzY6NDNaMB4CARICAQEEFhYUMjAxMy0wOC0wMVQwNzowMDowMFowQQIBBwIBAQQ5g8RXC0VL8JCqCTi1pxOIyv/ZJRsukymatvDJGhALBUHWOplLmpsZy4vcgC1cIpOVcooNg8JcbeJDMFgCAQYCAQEEUOBY1PXnuP8l20SwT0bMOcWf9H9Xo6lxxSVDuDrOlAiHm5Pcju4eWs7iAVJOkItqhVt0gRMveJDryC1iokiqOyUC87OSM/RElc6lljTb+yOlMIIBbQIBEQIBAQSCAWMxggFfMAsCAgatAgEBBAIMADALAgIGsAIBAQQCFgAwCwICBrICAQEEAgwAMAsCAgazAgEBBAIMADALAgIGtAIBAQQCDAAwCwICBrUCAQEEAgwAMAsCAga2AgEBBAIMADAMAgIGpQIBAQQDAgEBMAwCAgarAgEBBAMCAQMwDAICBq4CAQEEAwIBADAMAgIGsQIBAQQDAgEAMBICAgavAgEBBAkCBwONfqb
除非我解码,否则我无法理解它。但是,我已尝试安装base64
npm包和utf8
包,但它抱怨_utf2.default.decode is not a function. (In \'_utf2.default.decode(bytes)\', \'_utf2.default.decode\' is undefined)
。
https://github.com/mathiasbynens/base64 https://github.com/mathiasbynens/utf8.js#utf8decodebytestring
import base64 from 'base-64';
import utf8 from 'utf8';
const bytes = base64.decode(validationData);
const text = utf8.decode(bytes); // <----- fails here
console.log("base64: ", text);
背景:尝试使用以下方法在应用内购买:https://github.com/chirag04/react-native-in-app-utils,但receiptData
是base64编码
答案 0 :(得分:1)
如果您正在尝试对其进行解码并将其渲染为图像组件,则可以这样做:
const base64 = 'data:image/png;base64, *put your string here*'
<Image source={{uri: base64}} />
答案 1 :(得分:1)
我遇到了同样的问题。
I found this repository,看起来很旧,但也很有效。我没有收到标题(我不需要),但我确实收到了有效载荷/数据。
我做了以下事情:
npm install jwt-decode --save
然后,在我的应用中:
var jwtDecode = require('jwt-decode');
// Where necessary elsewhere in the code
let decoded = jwtDecode(token);
console.log('Decoded:',decoded);