如何将 Perl 的 Convert::ASN1 转换为 Ruby 代码?
有人可以告诉我这段代码的作用以及如何以最简单的方式将其转换为 Ruby 吗?
#!perl
use Convert::ASN1;
my $asn1 = Convert::ASN1->new(encoding => 'DER');
$asn1->prepare(q<
Algorithm ::= SEQUENCE {
oid OBJECT IDENTIFIER,
opt ANY OPTIONAL
}
Signature ::= SEQUENCE {
alg Algorithm,
sig BIT STRING
}
>);
my $data = $asn1->encode(sig => $body,
alg => {oid => sha512WithRSAEncryption()});
它是 Perl 库 mexumgen 的一部分,它使用 openssl 为 Mozilla 产品签署 update.rdf 。
Can somebody advise me what this code does and how can I convert it to Ruby in most simple way?
#!perl
use Convert::ASN1;
my $asn1 = Convert::ASN1->new(encoding => 'DER');
$asn1->prepare(q<
Algorithm ::= SEQUENCE {
oid OBJECT IDENTIFIER,
opt ANY OPTIONAL
}
Signature ::= SEQUENCE {
alg Algorithm,
sig BIT STRING
}
>);
my $data = $asn1->encode(sig => $body,
alg => {oid => sha512WithRSAEncryption()});
It's a piece of a mexumgen, Perl library which sign update.rdf for Mozilla products with openssl.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此特定示例可以转换为
其中“308191300b06092a864886f70d01010d03818100”是从该 ASN 表达式到 BIT STRING 字段(包括 BIT STRING 的大小)组成的前缀,pack("H") 将二进制数据转换为十六进制表示并 unpack("H")将十六进制字符串转换回二进制。
但对于更通用的 ASN 转换器,最好使用 OpenSSL::ASN1,它附带 ruby 作为标准库。 它完全没有记录,但有些人设法使用它< /a>
This particular example can be converted as
where "308191300b06092a864886f70d01010d03818100" is prefix made from that ASN expression up to BIT STRING field (including size of BIT STRING), pack("H") converts binary data to hex representation and unpack("H") converts string in hex back to binary.
But for more general ASN converter it's better to use OpenSSL::ASN1, which comes with ruby as standard library. It's completely undocumented but some people managed to have some use of it
您看过 Net::ASN1 吗?
Have you looked at Net::ASN1?