📄 pkcs-1.erl
字号:
%%------------------------------------------------- {EncBytes3,EncLen3} = ?RT_BER:encode_integer([], Cindex3, [<<2>>]), BytesSoFar = [EncBytes1, EncBytes2, EncBytes3],LenSoFar = EncLen1 + EncLen2 + EncLen3,?RT_BER:encode_tags(TagIn, BytesSoFar, LenSoFar).'dec_OtherPrimeInfo'(Tlv) -> 'dec_OtherPrimeInfo'(Tlv, [16]).'dec_OtherPrimeInfo'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%-------------------------------------------------Tlv1 = ?RT_BER:match_tags(Tlv,TagIn), %%-------------------------------------------------%% attribute prime(1) with type INTEGER%%-------------------------------------------------[V1|Tlv2] = Tlv1, Term1 = ?RT_BER:decode_integer(V1,[],[2]),%%-------------------------------------------------%% attribute exponent(2) with type INTEGER%%-------------------------------------------------[V2|Tlv3] = Tlv2, Term2 = ?RT_BER:decode_integer(V2,[],[2]),%%-------------------------------------------------%% attribute coefficient(3) with type INTEGER%%-------------------------------------------------[V3|Tlv4] = Tlv3, Term3 = ?RT_BER:decode_integer(V3,[],[2]),case Tlv4 of[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowedend, {'OtherPrimeInfo', Term1, Term2, Term3}.%%================================%% Algorithm%%================================'enc_Algorithm'(Val) -> 'enc_Algorithm'(Val, [<<48>>]).'enc_Algorithm'(Val, TagIn) ->{_,Cindex1, Cindex2} = Val,%%-------------------------------------------------%% attribute algorithm(1) with type OBJECT IDENTIFIER%%------------------------------------------------- {EncBytes1,EncLen1} = ?RT_BER:encode_object_identifier(Cindex1, [<<6>>]),%%-------------------------------------------------%% attribute parameters(2) with type ASN1_OPEN_TYPE OPTIONAL%%------------------------------------------------- {EncBytes2,EncLen2} = case Cindex2 of asn1_NOVALUE -> {<<>>,0}; _ -> ?RT_BER:encode_open_type(Cindex2, []) end, BytesSoFar = [EncBytes1, EncBytes2],LenSoFar = EncLen1 + EncLen2,?RT_BER:encode_tags(TagIn, BytesSoFar, LenSoFar).'dec_Algorithm'(Tlv) -> 'dec_Algorithm'(Tlv, [16]).'dec_Algorithm'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%-------------------------------------------------Tlv1 = ?RT_BER:match_tags(Tlv,TagIn), %%-------------------------------------------------%% attribute algorithm(1) with type OBJECT IDENTIFIER%%-------------------------------------------------[V1|Tlv2] = Tlv1, Term1 = ?RT_BER:decode_object_identifier(V1,[6]),%%-------------------------------------------------%% attribute parameters(2) with type ASN1_OPEN_TYPE OPTIONAL%%-------------------------------------------------{Term2,Tlv3} = case Tlv2 of[V2|TempTlv3] -> {?RT_BER:decode_open_type_as_binary(V2,[]), TempTlv3}; _ -> { asn1_NOVALUE, Tlv2}end,case Tlv3 of[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowedend, {'Algorithm', Term1, Term2}.%%================================%% AlgorithmNull%%================================'enc_AlgorithmNull'(Val) -> 'enc_AlgorithmNull'(Val, [<<48>>]).'enc_AlgorithmNull'(Val, TagIn) ->{_,Cindex1, Cindex2} = Val,%%-------------------------------------------------%% attribute algorithm(1) with type OBJECT IDENTIFIER%%------------------------------------------------- {EncBytes1,EncLen1} = ?RT_BER:encode_object_identifier(Cindex1, [<<6>>]),%%-------------------------------------------------%% attribute parameters(2) with type NULL%%------------------------------------------------- {EncBytes2,EncLen2} = ?RT_BER:encode_null(Cindex2, [<<5>>]), BytesSoFar = [EncBytes1, EncBytes2],LenSoFar = EncLen1 + EncLen2,?RT_BER:encode_tags(TagIn, BytesSoFar, LenSoFar).'dec_AlgorithmNull'(Tlv) -> 'dec_AlgorithmNull'(Tlv, [16]).'dec_AlgorithmNull'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%-------------------------------------------------Tlv1 = ?RT_BER:match_tags(Tlv,TagIn), %%-------------------------------------------------%% attribute algorithm(1) with type OBJECT IDENTIFIER%%-------------------------------------------------[V1|Tlv2] = Tlv1, Term1 = ?RT_BER:decode_object_identifier(V1,[6]),%%-------------------------------------------------%% attribute parameters(2) with type NULL%%-------------------------------------------------[V2|Tlv3] = Tlv2, Term2 = ?RT_BER:decode_null(V2,[5]),case Tlv3 of[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowedend, {'AlgorithmNull', Term1, Term2}.%%================================%% RSASSA-PSS-params%%================================'enc_RSASSA-PSS-params'(Val) -> 'enc_RSASSA-PSS-params'(Val, [<<48>>]).'enc_RSASSA-PSS-params'(Val, TagIn) ->{_,Cindex1, Cindex2, Cindex3, Cindex4} = Val,%%-------------------------------------------------%% attribute hashAlgorithm(1) External PKCS-1:Algorithm%%------------------------------------------------- {EncBytes1,EncLen1} = 'enc_Algorithm'(Cindex1, [<<48>>,<<160>>]),%%-------------------------------------------------%% attribute maskGenAlgorithm(2) External PKCS-1:Algorithm%%------------------------------------------------- {EncBytes2,EncLen2} = 'enc_Algorithm'(Cindex2, [<<48>>,<<161>>]),%%-------------------------------------------------%% attribute saltLength(3) with type INTEGER DEFAULT = 20%%------------------------------------------------- {EncBytes3,EncLen3} = case catch asn1rt_check:check_int(20, Cindex3, []) of true -> {[],0}; _ -> ?RT_BER:encode_integer([], Cindex3, [<<2>>,<<162>>]) end,%%-------------------------------------------------%% attribute trailerField(4) with type INTEGER DEFAULT = 1%%------------------------------------------------- {EncBytes4,EncLen4} = case catch asn1rt_check:check_int(1, Cindex4, [{trailerFieldBC,1}]) of true -> {[],0}; _ -> ?RT_BER:encode_integer([], Cindex4, [{trailerFieldBC,1}], [<<2>>,<<163>>]) end, BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4],LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4,?RT_BER:encode_tags(TagIn, BytesSoFar, LenSoFar).'dec_RSASSA-PSS-params'(Tlv) -> 'dec_RSASSA-PSS-params'(Tlv, [16]).'dec_RSASSA-PSS-params'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%-------------------------------------------------Tlv1 = ?RT_BER:match_tags(Tlv,TagIn), %%-------------------------------------------------%% attribute hashAlgorithm(1) External PKCS-1:Algorithm%%-------------------------------------------------[V1|Tlv2] = Tlv1, Term1 = 'dec_Algorithm'(V1, [131072,16]),%%-------------------------------------------------%% attribute maskGenAlgorithm(2) External PKCS-1:Algorithm%%-------------------------------------------------[V2|Tlv3] = Tlv2, Term2 = 'dec_Algorithm'(V2, [131073,16]),%%-------------------------------------------------%% attribute saltLength(3) with type INTEGER DEFAULT = 20%%-------------------------------------------------{Term3,Tlv4} = case Tlv3 of[{131074,V3}|TempTlv4] -> {?RT_BER:decode_integer(V3,[],[2]), TempTlv4}; _ -> {20,Tlv3}end,%%-------------------------------------------------%% attribute trailerField(4) with type INTEGER DEFAULT = 1%%-------------------------------------------------{Term4,Tlv5} = case Tlv4 of[{131075,V4}|TempTlv5] -> {?RT_BER:decode_integer(V4,[],[{trailerFieldBC,1}],[2]), TempTlv5}; _ -> {1,Tlv4}end,case Tlv5 of[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv5}}}) % extra fields not allowedend, {'RSASSA-PSS-params', Term1, Term2, Term3, Term4}.%%================================%% TrailerField%%================================'enc_TrailerField'(Val) -> 'enc_TrailerField'(Val, [<<2>>]).'enc_TrailerField'({'TrailerField',Val}, TagIn) -> 'enc_TrailerField'(Val, TagIn);'enc_TrailerField'(Val, TagIn) ->?RT_BER:encode_integer([], Val, [{trailerFieldBC,1}], TagIn).'dec_TrailerField'(Tlv) -> 'dec_TrailerField'(Tlv, [2]).'dec_TrailerField'(Tlv, TagIn) ->?RT_BER:decode_integer(Tlv,[],[{trailerFieldBC,1}],TagIn).%%================================%% DigestInfo%%================================'enc_DigestInfo'(Val) -> 'enc_DigestInfo'(Val, [<<48>>]).'enc_DigestInfo'(Val, TagIn) ->{_,Cindex1, Cindex2} = Val,%%-------------------------------------------------%% attribute digestAlgorithm(1) External PKCS-1:Algorithm%%------------------------------------------------- {EncBytes1,EncLen1} = 'enc_Algorithm'(Cindex1, [<<48>>]),%%-------------------------------------------------%% attribute digest(2) with type OCTET STRING%%------------------------------------------------- {EncBytes2,EncLen2} = ?RT_BER:encode_octet_string([], Cindex2, [<<4>>]), BytesSoFar = [EncBytes1, EncBytes2],LenSoFar = EncLen1 + EncLen2,?RT_BER:encode_tags(TagIn, BytesSoFar, LenSoFar).'dec_DigestInfo'(Tlv) -> 'dec_DigestInfo'(Tlv, [16]).'dec_DigestInfo'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%-------------------------------------------------Tlv1 = ?RT_BER:match_tags(Tlv,TagIn), %%-------------------------------------------------%% attribute digestAlgorithm(1) External PKCS-1:Algorithm%%-------------------------------------------------[V1|Tlv2] = Tlv1, Term1 = 'dec_Algorithm'(V1, [16]),%%-------------------------------------------------%% attribute digest(2) with type OCTET STRING%%-------------------------------------------------[V2|Tlv3] = Tlv2, Term2 = ?RT_BER:decode_octet_string(V2,[],[4]),case Tlv3 of[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowedend, {'DigestInfo', Term1, Term2}.%%================================%% DigestInfoNull%%================================'enc_DigestInfoNull'(Val) -> 'enc_DigestInfoNull'(Val, [<<48>>]).'enc_DigestInfoNull'(Val, TagIn) ->{_,Cindex1, Cindex2} = Val,%%-------------------------------------------------%% attribute digestAlgorithm(1) External PKCS-1:AlgorithmNull%%------------------------------------------------- {EncBytes1,EncLen1} = 'enc_AlgorithmNull'(Cindex1, [<<48>>]),%%-------------------------------------------------%% attribute digest(2) with type OCTET STRING%%------------------------------------------------- {EncBytes2,EncLen2} = ?RT_BER:encode_octet_string([], Cindex2, [<<4>>]), BytesSoFar = [EncBytes1, EncBytes2],LenSoFar = EncLen1 + EncLen2,?RT_BER:encode_tags(TagIn, BytesSoFar, LenSoFar).'dec_DigestInfoNull'(Tlv) -> 'dec_DigestInfoNull'(Tlv, [16]).'dec_DigestInfoNull'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%-------------------------------------------------Tlv1 = ?RT_BER:match_tags(Tlv,TagIn), %%-------------------------------------------------%% attribute digestAlgorithm(1) External PKCS-1:AlgorithmNull%%-------------------------------------------------[V1|Tlv2] = Tlv1, Term1 = 'dec_AlgorithmNull'(V1, [16]),%%-------------------------------------------------%% attribute digest(2) with type OCTET STRING%%-------------------------------------------------[V2|Tlv3] = Tlv2, Term2 = ?RT_BER:decode_octet_string(V2,[],[4]),case Tlv3 of[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowedend, {'DigestInfoNull', Term1, Term2}.'pkcs-1'() ->{1,2,840,113549,1,1}.'rsaEncryption'() ->{1,2,840,113549,1,1,1}.'id-RSAES-OAEP'() ->{1,2,840,113549,1,1,7}.'id-pSpecified'() ->{1,2,840,113549,1,1,9}.'id-RSASSA-PSS'() ->{1,2,840,113549,1,1,10}.'md2WithRSAEncryption'() ->{1,2,840,113549,1,1,2}.'md5WithRSAEncryption'() ->{1,2,840,113549,1,1,4}.'sha1WithRSAEncryption'() ->{1,2,840,113549,1,1,5}.'sha256WithRSAEncryption'() ->{1,2,840,113549,1,1,11}.'sha384WithRSAEncryption'() ->{1,2,840,113549,1,1,12}.'sha512WithRSAEncryption'() ->{1,2,840,113549,1,1,13}.'id-sha1'() ->{1,3,14,3,2,26}.'id-md2'() ->{1,2,840,113549,2,2}.'id-md5'() ->{1,2,840,113549,2,5}.'id-mgf1'() ->{1,2,840,113549,1,1,8}.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -