Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Perl中将非ANSI字符转换为Crypt::Blowfish?_Perl_Utf 8_Ansi_Blowfish - Fatal编程技术网

如何在Perl中将非ANSI字符转换为Crypt::Blowfish?

如何在Perl中将非ANSI字符转换为Crypt::Blowfish?,perl,utf-8,ansi,blowfish,Perl,Utf 8,Ansi,Blowfish,如何在Perl中将非ANSI字符转换为Crypt::Blowfish 以下脚本是用字符集UTF-8编写的,仅在§orö上失败 许多Crypt::*模块都是块加密算法。因此,它们只能使用固定长度的块。由于“§”是UTF8字符,它实际上包含超过1个字节,这就是代码失败的原因。另一个问题是使用utf8 pragma,这意味着将使用utf8标志创建utf8常量字符串。这可能导致二进制算法的重大变化,如加密 我建议您使用Crypt::CBC模块在CPAN上检查它;并且,在加密之前删除utf8标志:utf8

如何在Perl中将非ANSI字符转换为Crypt::Blowfish

以下脚本是用字符集UTF-8编写的,仅在§orö上失败


许多Crypt::*模块都是块加密算法。因此,它们只能使用固定长度的块。由于“§”是UTF8字符,它实际上包含超过1个字节,这就是代码失败的原因。另一个问题是使用utf8 pragma,这意味着将使用utf8标志创建utf8常量字符串。这可能导致二进制算法的重大变化,如加密


我建议您使用Crypt::CBC模块在CPAN上检查它;并且,在加密之前删除utf8标志:utf8::encode$\

许多Crypt::*模块都是块加密算法。因此,它们只能使用固定长度的块。由于“§”是UTF8字符,它实际上包含超过1个字节,这就是代码失败的原因。另一个问题是使用utf8 pragma,这意味着将使用utf8标志创建utf8常量字符串。这可能导致二进制算法的重大变化,如加密


我建议您使用Crypt::CBC模块在CPAN上检查它;并且,在加密之前删除utf8标志:utf8::encode$\

密码在字节流或字节块上工作,但您没有为其提供字节。您正在为它提供Unicode处理点

您需要将要加密的任何文本序列化为字节,然后才能对其进行加密,也就是说,您需要对文本进行编码

use Encode qw( encode_utf8 );
my $bytes = encode_utf8($char x 8);
此外,您不应该直接使用。这将产生弱加密。你想通过网络访问它。这提供了盐渍、链结和填充

use Crypt::CBC qw( );
use Encode     qw( encode_utf8 decode_utf8 );

my $cipher = Crypt::CBC->new(
   -key    => '... key phrase ...',
   -cipher => 'Blowfish',
);

my $cipher_bytes = $cipher->encrypt(encode_utf8($plain_text));
my $plain_text = decode_utf8($cipher->decrypt($cipher_bytes));

密码在流或字节块上工作,但您没有为其提供字节。您正在为它提供Unicode处理点

您需要将要加密的任何文本序列化为字节,然后才能对其进行加密,也就是说,您需要对文本进行编码

use Encode qw( encode_utf8 );
my $bytes = encode_utf8($char x 8);
此外,您不应该直接使用。这将产生弱加密。你想通过网络访问它。这提供了盐渍、链结和填充

use Crypt::CBC qw( );
use Encode     qw( encode_utf8 decode_utf8 );

my $cipher = Crypt::CBC->new(
   -key    => '... key phrase ...',
   -cipher => 'Blowfish',
);

my $cipher_bytes = $cipher->encrypt(encode_utf8($plain_text));
my $plain_text = decode_utf8($cipher->decrypt($cipher_bytes));