简体   繁体   English

base64的自定义映射表

[英]custom mapping table for base64

i need to use base 64 to encrypt some data.我需要使用 base 64 来加密一些数据。 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+/"所以我需要使用自定义映射表来编码“ABCD......789+/”的insted

i found a function at php.net - http://www.php.net/manual/en/function.base64-encode.php#78765我在 php.net - http://www.php.net/manual/en/function.base64-encode.php#78765找到了 function

it can do what i need but i don't know how to decode the encrypted data.它可以做我需要的,但我不知道如何解码加密数据。

base64 encryption really isn't for security. base64 加密确实不是为了安全。 You want to use mcrypt or similar for that.你想为此使用mcrypt或类似的东西。 base64 is specifically for transferring data in a way that is safe and can be understood by multiple interested parties. base64 专门用于以安全且可被多个相关方理解的方式传输数据。

But, here is how you'd go about undoing that poster's method:但是,这里是你如何 go 关于撤消该海报的方法:

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).如果你看他的评论,他换了's'和9(实际上,他的数组有两个'S',但我认为第二个是错字)。 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 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM