line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Webqq::Encryption::RSA; |
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
3
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
146
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
BEGIN{ |
6
|
1
|
|
|
1
|
|
3
|
eval{ |
7
|
1
|
|
|
|
|
400
|
require Crypt::OpenSSL::RSA; |
8
|
1
|
|
|
|
|
5383
|
require Crypt::OpenSSL::Bignum; |
9
|
|
|
|
|
|
|
}; |
10
|
1
|
50
|
|
|
|
3
|
unless($@){ |
11
|
1
|
|
|
|
|
396
|
$Webqq::Encryption::RSA::has_crypt_openssl_rsa = 1; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
else{ |
14
|
0
|
|
|
|
|
0
|
eval{ |
15
|
0
|
|
|
|
|
0
|
require Crypt::RSA::ES::PKCS1v15; |
16
|
0
|
|
|
|
|
0
|
require Crypt::RSA::Key::Public; |
17
|
|
|
|
|
|
|
}; |
18
|
0
|
0
|
|
|
|
0
|
unless($@){ |
19
|
0
|
|
|
|
|
0
|
$Webqq::Encryption::RSA::has_crypt_rsa = 1; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
else{ |
22
|
0
|
|
|
|
|
0
|
eval{require JE;}; |
|
0
|
|
|
|
|
0
|
|
23
|
0
|
0
|
|
|
|
0
|
unless($@){ |
24
|
0
|
|
|
|
|
0
|
$Webqq::Encryption::RSA::has_je = 1; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else{ |
27
|
0
|
|
|
|
|
0
|
croak "You must install Crypt::RSA or Crypt::OpenSSL::RSA or JE module to support rsa encrypt\n"; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub encrypt { |
35
|
0
|
|
|
0
|
0
|
|
my $data = shift; |
36
|
0
|
0
|
|
|
|
|
if($Webqq::Encryption::RSA::has_crypt_rsa){ |
|
|
0
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $n = "0xE9A815AB9D6E86ABBF33A4AC64E9196D5BE44A09BD0ED6AE052914E1A865AC8331FED863DE8EA697E9A7F63329E5E23CDA09C72570F46775B7E39EA9670086F847D3C9C51963B131409B1E04265D9747419C635404CA651BBCBC87F99B8008F7F5824653E3658BE4BA73E4480156B390BB73BC1F8B33578E7A4E12440E9396F2552C1AFF1C92E797EBACDC37C109AB7BCE2367A19C56A033EE04534723CC2558CB27368F5B9D32C04D12DBD86BBD68B1D99B7C349A8453EA75D1B2E94491AB30ACF6C46A36A75B721B312BEDF4E7AAD21E54E9BCBCF8144C79B6E3C05EB4A1547750D224C0085D80E6DA3907C3D945051C13C7C1DCEFD6520EE8379C4F5231ED"; |
38
|
0
|
|
|
|
|
|
my $public = Crypt::RSA::Key::Public->new(); |
39
|
0
|
|
|
|
|
|
$public->e("0x10001"); |
40
|
0
|
|
|
|
|
|
$public->n($n); |
41
|
0
|
|
|
|
|
|
my $rsa = Crypt::RSA::ES::PKCS1v15->new(); |
42
|
0
|
|
|
|
|
|
return lc join "",unpack "H*", $rsa->encrypt(Message=>$data,Key=>$public,); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
elsif($Webqq::Encryption::RSA::has_crypt_openssl_rsa){ |
45
|
0
|
|
|
|
|
|
my $n = Crypt::OpenSSL::Bignum->new_from_hex("E9A815AB9D6E86ABBF33A4AC64E9196D5BE44A09BD0ED6AE052914E1A865AC8331FED863DE8EA697E9A7F63329E5E23CDA09C72570F46775B7E39EA9670086F847D3C9C51963B131409B1E04265D9747419C635404CA651BBCBC87F99B8008F7F5824653E3658BE4BA73E4480156B390BB73BC1F8B33578E7A4E12440E9396F2552C1AFF1C92E797EBACDC37C109AB7BCE2367A19C56A033EE04534723CC2558CB27368F5B9D32C04D12DBD86BBD68B1D99B7C349A8453EA75D1B2E94491AB30ACF6C46A36A75B721B312BEDF4E7AAD21E54E9BCBCF8144C79B6E3C05EB4A1547750D224C0085D80E6DA3907C3D945051C13C7C1DCEFD6520EE8379C4F5231ED"); |
46
|
0
|
|
|
|
|
|
my $e = Crypt::OpenSSL::Bignum->new_from_hex("10001"); |
47
|
0
|
|
|
|
|
|
my $rsa = Crypt::OpenSSL::RSA->new_key_from_parameters($n,$e); |
48
|
0
|
|
|
|
|
|
$rsa->use_pkcs1_padding(); |
49
|
0
|
|
|
|
|
|
return lc join "",unpack "H*", $rsa->encrypt($data); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$data = join "",map {"\\x$_"} unpack "H2"x length($data),$data; |
|
0
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $je; |
54
|
0
|
0
|
|
|
|
|
if(defined $Webqq::Encryption::RSA::_je ){ |
55
|
0
|
|
|
|
|
|
$je = $Webqq::Encryption::RSA::_je ; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else{ |
58
|
0
|
|
|
|
|
|
my $javascript; |
59
|
0
|
0
|
|
|
|
|
if(defined $Webqq::Encryption::RSA::_javascript){ |
60
|
0
|
|
|
|
|
|
$javascript = $Webqq::Encryption::RSA::_javascript; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else{ |
63
|
0
|
|
|
|
|
|
local $/ = undef; |
64
|
0
|
|
|
|
|
|
$javascript = ; |
65
|
0
|
|
|
|
|
|
$Webqq::Encryption::RSA::_javascript = $javascript; |
66
|
0
|
|
|
|
|
|
close DATA; |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
$je = JE->new; |
69
|
0
|
|
|
|
|
|
$je->eval($javascript); |
70
|
0
|
0
|
|
|
|
|
croak "Webqq::Encryption::RSA load javascript error: $@\n" if $@; |
71
|
0
|
|
|
|
|
|
$Webqq::Encryption::RSA::_je = $je; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
#print qq# |
75
|
|
|
|
|
|
|
# var rsa = RSA(); |
76
|
|
|
|
|
|
|
# var r = rsa.rsa_encrypt('$data'); |
77
|
|
|
|
|
|
|
# return(r); |
78
|
|
|
|
|
|
|
##; |
79
|
0
|
|
|
|
|
|
my $p = $je->eval(qq# |
80
|
|
|
|
|
|
|
var rsa = RSA(); |
81
|
|
|
|
|
|
|
var r = rsa.rsa_encrypt('$data'); |
82
|
|
|
|
|
|
|
return(r); |
83
|
|
|
|
|
|
|
#); |
84
|
0
|
0
|
0
|
|
|
|
if($p and !$@){ |
85
|
0
|
|
|
|
|
|
return $p; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
else{ |
88
|
0
|
|
|
|
|
|
croak "Webqq::Encryption::RSA error: $@\n"; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
__DATA__ |