<head>
<!-- hexo-ignore-start -->
<style>
.custom-input {
margin-bottom: 20px;
}
.custom-textarea {
width: 100%;
margin-bottom: 20px;
}
</style>
<!-- hexo-ignore-end -->
</head>
<div class="tools wrap">
<!-- hexo-ignore-start -->
<div class="breadcrumb" itemscope="" itemtype="https://schema.org/BreadcrumbList">
<i class="ic i-home"></i>
<span><a href="/" data-pjax-state=""> 首页 </a></span>
<i class="ic i-angle-right"></i>
<span itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem">
<a href="/tools/" itemprop="item" rel="index" title="工具" data-pjax-state=""><span itemprop="name"> 工具 </span></a>
<meta itemprop="position" content="1">
</span>
<i class="ic i-angle-right"></i>
<span class="current" itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem">
<a href="/tools/base64/" itemprop="item" rel="index" title="BASE64 加解密" data-pjax-state=""><span itemprop="name">BASE64 加解密 </span></a>
<meta itemprop="position" content="2">
</span>
</div>
<!-- hexo-ignore-end -->
<div class="tools cloud">
<!-- hexo-ignore-start -->
信息:<textarea class="custom-textarea" rows="4" cols="50" id="content"></textarea><br>
加密结果:<textarea class="custom-textarea" rows="4" cols="50" id="value1"></textarea><br>
解密结果:<textarea class="custom-textarea" rows="4" cols="50" id="value2"></textarea><br>
<input type="button" value="加密" onclick="submit (1)" />
<input type="button" value="解密" onclick="submit (0)" />
<script>
// 提交
function submit (type) {
if (type == 1) {
document.getElementById("value1").value = "";
// 加密
var text = document.getElementById ("content").value;
if (!text) {
alert ("信息不能为空");
return;
}
document.getElementById("value1").value = btoaStr(text);
} else {
document.getElementById("value2").value = "";
// 解密
var encryptionText = document.getElementById ("value1").value;
if (!encryptionText) {
alert ("加密结果不能为空");
return;
}
document.getElementById("value2").value = atobStr(encryptionText);
}
}

		// 加密
		function btoaStr(str) {
			let encoder = new TextEncoder();
			let bytes = encoder.encode(str);
			let base64 = btoa(String.fromCharCode.apply(null, bytes));
			return base64;
		}

		// 解密
		function atobStr(base64) {
			let bytes = atob(base64).split('').map(function (c) {
				return c.charCodeAt(0);
			});
			let decoder = new TextDecoder();
			let decodedString = decoder.decode(new Uint8Array(bytes));
			return decodedString;
		}
	</script>
	<!-- hexo-ignore-end -->
</div>

</div>

更新于 阅读次数

请我喝[茶]~( ̄▽ ̄)~*

Hito Li 微信支付

微信支付

Hito Li 支付宝

支付宝