6 Star 0 Fork 0

OpenCloudOS Stream/perl-Crypt-CBC

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
cbctest1.pl 1.66 KB
一键复制 编辑 原始数据 按行查看 历史
fanjunkong 提交于 2024-06-26 15:25 . update
#!/usr/bin/perl
use strict;
use warnings;
use Carp;
use Encode;
# small script for Blowfish encryption and decryption
# The key for the blowfish encoding/decoding below
my $privateString = '123456789012345678901234567890123456789012';
my $teststring = "Testtext";
my $encoded = encodeBlowfish($teststring);
my $decoded = decodeBlowfish($encoded);
print "original: $teststring\n";
print "encoded: $encoded\n";
print "decoded: $decoded\n";
#
# Encode a string using blowfish with a private key.
#
sub encodeBlowfish
{
my($string) = @_;
my $cipher = undef;
eval
{
require Crypt::CBC;
my $key = pack('H*', $privateString);
my $params = { 'key' => $key, 'cipher' => 'Blowfish', 'header' => 'randomiv'};
$cipher = new Crypt::CBC($params);
};
if ($@)
{
warn("*********** $@\n");
}
my $enc = undef;
if (defined($cipher))
{
if (Encode::is_utf8($string))
{
#
# workaround Blowfish problem with utf8-flag
#
Encode::_utf8_off($string);
}
$enc = $cipher->encrypt_hex($string);
}
return $enc;
}
#
# Decode a string using blowfish with a private key.
#
sub decodeBlowfish
{
my($string) = @_;
return undef if (!defined($string)); # filter empty strings for Blowfish
return '' if ($string eq '');
my $cipher = undef;
eval
{
require Crypt::CBC;
my $key = pack('H*', $privateString);
my $params = { 'key' => $key, 'cipher' => 'Blowfish', 'header' => 'randomiv'};
$cipher = new Crypt::CBC($params);
};
my $enc = undef;
if (defined($cipher))
{
$enc = $cipher->decrypt_hex($string);
}
return $enc;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/opencloudos-stream/perl-Crypt-CBC.git
git@gitee.com:opencloudos-stream/perl-Crypt-CBC.git
opencloudos-stream
perl-Crypt-CBC
perl-Crypt-CBC
master

搜索帮助