angular - 以角度 6 将 Base64 转换为十六进制
问题描述
请您帮我解决将base64值转换为十六进制的问题,反之亦然。我目前正在研究 angular 6,似乎无法在任何地方找到解决方案。
解决方案
这是您可以用于转换的功能
hexAndBase64(strInput, conversionType) {
if (conversionType == "64ToHex") {
for (var i = 0, bin = atob(strInput.replace(/[ \r\n]+$/, "")), hex = []; i < bin.length; ++i) {
let tmp = bin.charCodeAt(i).toString(16);
if (tmp.length === 1) tmp = "0" + tmp;
hex[hex.length] = tmp;
}
return hex.join(" ");
}
else if (conversionType == "hexTo64") {
return btoa(String.fromCharCode.apply(null,
strInput.replace(/\r|\n/g, "").replace(/([\da-fA-F]{2}) ?/g, "0x$1 ").replace(/ +$/, "").split(" ")));
}
}
推荐阅读
- html - 如何将 svg 图像修复到特定高度并保持响应?
- python - 超出顶级包的相对导入错误
- python - 如何根据与键关联的值列表创建字典?
- typescript - 如何在 TypeScript 中重新声明块范围的变量?
- jquery - 用于多个 HTML 元素的相同 CSS 类,由 JQuery 触发,但不是单独触发(涉及自定义 YouTube 播放按钮)
- python - 仅使用 python 列表将一段 2D 数组替换为另一个 2D 数组?
- css - 编码的 svg 背景图像不会在 css 动画中正确地无缝循环
- java - Maven 依赖错误 - 抱怨存储库中显示的依赖
- bootstrap-4 - Bootstrap 4 .nav-item 和 .nav-link 类
- jquery - 如何从外部数据源制作组织结构图