1

有人可以告诉我这段代码的作用以及如何以最简单的方式将其转换为 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()});

它是mexumgen的一部分,Perl 库为带有 openssl 的 Mozilla 产品签名 update.rdf。

4

2 回答 2

1

这个特定的例子可以转换为

data = ["308191300b06092a864886f70d01010d03818100" + body.unpack("H*")].pack("H*")

其中“308191300b06092a864886f70d01010d03818100”是从该 ASN 表达式到 BIT STRING 字段(包括 BIT STRING 的大小)的前缀,pack("H") 将二进制数据转换为十六进制表示,unpack("H") 将十六进制的字符串转换回二进制.

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

于 2008-12-25T15:52:07.633 回答
0

你看过Net::ASN1吗?

于 2008-12-24T10:55:14.973 回答