Base64 的自定义映射表

发布于 2024-11-19 03:07:51 字数 370 浏览 4 评论 0原文

我需要使用 Base 64 来加密一些数据。 但是,虽然每个人都可以解码它,但对其进行编码有意义吗?

所以我需要使用自定义映射表来编码insted of "ABCD......789+/"

我在php.net找到了一个函数 - http://www.php.net/manual/en/ function.base64-encode.php#78765

它可以做我需要的事情 但我不知道如何解码加密数据。

i need to use base 64 to encrypt some data.
but while everyone can decode it, does it make sense to encode it?

so i need to use custom maping table to encode insted of "ABCD......789+/"

i found a function at php.net -
http://www.php.net/manual/en/function.base64-encode.php#78765

it can do what i need
but i don't know how to decode the encrypted data.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏辞 2024-11-26 03:07:51

Base64 加密确实不是为了安全。您想使用 mcrypt 或类似的方法。 Base64 专门用于以安全且可以被多个相关方理解的方式传输数据。

但是,您可以按照以下方式撤销该海报的方法:

如果您查看他的评论,您会发现他交换了“s”和 9(实际上,他的数组有两个“S”,但我认为第二个是拼写错误)。所以这应该有效:

// there is a more efficient way of doing this, but this was easy to demonstrate.
// you'll need to use temp stand-ins 
$res = str_replace( array( 9, 's' ), array( '{', '}' ), $input ); 
$res = str_replace( array( '{', '}' ), array( 's', 9 ), $res ); 
$base64_raw = '';

for( $i = 0; $i < strlen( $res ); $i++ )
{
    $tmp = $res[ $i ];
    // if it is upper case, then append the lower-case version.
    if( $tmp == strtoupper( $tmp ) ) $base64_raw .= strtolower( $tmp );
    // else append the upper-case version.
    else $base64_raw .= strtoupper( $tmp );
}

echo base64_decode( $base64_raw );

base64 encryption really isn't for security. You want to use mcrypt or similar for that. base64 is specifically for transferring data in a way that is safe and can be understood by multiple interested parties.

But, here is how you'd go about undoing that poster's method:

If you look at his comments, he's switched 's' and 9 (actually, his array has two 'S', but I think the second was a typo). So this should work:

// there is a more efficient way of doing this, but this was easy to demonstrate.
// you'll need to use temp stand-ins 
$res = str_replace( array( 9, 's' ), array( '{', '}' ), $input ); 
$res = str_replace( array( '{', '}' ), array( 's', 9 ), $res ); 
$base64_raw = '';

for( $i = 0; $i < strlen( $res ); $i++ )
{
    $tmp = $res[ $i ];
    // if it is upper case, then append the lower-case version.
    if( $tmp == strtoupper( $tmp ) ) $base64_raw .= strtolower( $tmp );
    // else append the upper-case version.
    else $base64_raw .= strtoupper( $tmp );
}

echo base64_decode( $base64_raw );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文