SignerUtilities.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections;
  5. using System.IO;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
  7. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Bsi;
  8. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.CryptoPro;
  9. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Eac;
  10. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.EdEC;
  11. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.GM;
  12. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
  13. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
  14. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
  15. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.TeleTrust;
  16. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  17. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
  18. using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
  19. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests;
  20. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
  21. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
  22. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
  23. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  24. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Security
  25. {
  26. /// <summary>
  27. /// Signer Utility class contains methods that can not be specifically grouped into other classes.
  28. /// </summary>
  29. public sealed class SignerUtilities
  30. {
  31. private SignerUtilities()
  32. {
  33. }
  34. internal static readonly IDictionary algorithms = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
  35. internal static readonly IDictionary oids = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
  36. static SignerUtilities()
  37. {
  38. algorithms["MD2WITHRSA"] = "MD2withRSA";
  39. algorithms["MD2WITHRSAENCRYPTION"] = "MD2withRSA";
  40. algorithms[PkcsObjectIdentifiers.MD2WithRsaEncryption.Id] = "MD2withRSA";
  41. algorithms["MD4WITHRSA"] = "MD4withRSA";
  42. algorithms["MD4WITHRSAENCRYPTION"] = "MD4withRSA";
  43. algorithms[PkcsObjectIdentifiers.MD4WithRsaEncryption.Id] = "MD4withRSA";
  44. algorithms[OiwObjectIdentifiers.MD4WithRsa.Id] = "MD4withRSA";
  45. algorithms[OiwObjectIdentifiers.MD4WithRsaEncryption.Id] = "MD4withRSA";
  46. algorithms["MD5WITHRSA"] = "MD5withRSA";
  47. algorithms["MD5WITHRSAENCRYPTION"] = "MD5withRSA";
  48. algorithms[PkcsObjectIdentifiers.MD5WithRsaEncryption.Id] = "MD5withRSA";
  49. algorithms[OiwObjectIdentifiers.MD5WithRsa.Id] = "MD5withRSA";
  50. algorithms["SHA1WITHRSA"] = "SHA-1withRSA";
  51. algorithms["SHA-1WITHRSA"] = "SHA-1withRSA";
  52. algorithms["SHA1WITHRSAENCRYPTION"] = "SHA-1withRSA";
  53. algorithms["SHA-1WITHRSAENCRYPTION"] = "SHA-1withRSA";
  54. algorithms[PkcsObjectIdentifiers.Sha1WithRsaEncryption.Id] = "SHA-1withRSA";
  55. algorithms[OiwObjectIdentifiers.Sha1WithRsa.Id] = "SHA-1withRSA";
  56. algorithms["SHA224WITHRSA"] = "SHA-224withRSA";
  57. algorithms["SHA-224WITHRSA"] = "SHA-224withRSA";
  58. algorithms["SHA224WITHRSAENCRYPTION"] = "SHA-224withRSA";
  59. algorithms["SHA-224WITHRSAENCRYPTION"] = "SHA-224withRSA";
  60. algorithms[PkcsObjectIdentifiers.Sha224WithRsaEncryption.Id] = "SHA-224withRSA";
  61. algorithms["SHA256WITHRSA"] = "SHA-256withRSA";
  62. algorithms["SHA-256WITHRSA"] = "SHA-256withRSA";
  63. algorithms["SHA256WITHRSAENCRYPTION"] = "SHA-256withRSA";
  64. algorithms["SHA-256WITHRSAENCRYPTION"] = "SHA-256withRSA";
  65. algorithms[PkcsObjectIdentifiers.Sha256WithRsaEncryption.Id] = "SHA-256withRSA";
  66. algorithms["SHA384WITHRSA"] = "SHA-384withRSA";
  67. algorithms["SHA-384WITHRSA"] = "SHA-384withRSA";
  68. algorithms["SHA384WITHRSAENCRYPTION"] = "SHA-384withRSA";
  69. algorithms["SHA-384WITHRSAENCRYPTION"] = "SHA-384withRSA";
  70. algorithms[PkcsObjectIdentifiers.Sha384WithRsaEncryption.Id] = "SHA-384withRSA";
  71. algorithms["SHA512WITHRSA"] = "SHA-512withRSA";
  72. algorithms["SHA-512WITHRSA"] = "SHA-512withRSA";
  73. algorithms["SHA512WITHRSAENCRYPTION"] = "SHA-512withRSA";
  74. algorithms["SHA-512WITHRSAENCRYPTION"] = "SHA-512withRSA";
  75. algorithms[PkcsObjectIdentifiers.Sha512WithRsaEncryption.Id] = "SHA-512withRSA";
  76. algorithms["SHA512(224)WITHRSA"] = "SHA-512(224)withRSA";
  77. algorithms["SHA-512(224)WITHRSA"] = "SHA-512(224)withRSA";
  78. algorithms["SHA512(224)WITHRSAENCRYPTION"] = "SHA-512(224)withRSA";
  79. algorithms["SHA-512(224)WITHRSAENCRYPTION"] = "SHA-512(224)withRSA";
  80. algorithms[PkcsObjectIdentifiers.Sha512_224WithRSAEncryption.Id] = "SHA-512(224)withRSA";
  81. algorithms["SHA512(256)WITHRSA"] = "SHA-512(256)withRSA";
  82. algorithms["SHA-512(256)WITHRSA"] = "SHA-512(256)withRSA";
  83. algorithms["SHA512(256)WITHRSAENCRYPTION"] = "SHA-512(256)withRSA";
  84. algorithms["SHA-512(256)WITHRSAENCRYPTION"] = "SHA-512(256)withRSA";
  85. algorithms[PkcsObjectIdentifiers.Sha512_256WithRSAEncryption.Id] = "SHA-512(256)withRSA";
  86. algorithms["SHA3-224WITHRSA"] = "SHA3-224withRSA";
  87. algorithms["SHA3-224WITHRSAENCRYPTION"] = "SHA3-224withRSA";
  88. algorithms[NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_224.Id] = "SHA3-224withRSA";
  89. algorithms["SHA3-256WITHRSA"] = "SHA3-256withRSA";
  90. algorithms["SHA3-256WITHRSAENCRYPTION"] = "SHA3-256withRSA";
  91. algorithms[NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_256.Id] = "SHA3-256withRSA";
  92. algorithms["SHA3-384WITHRSA"] = "SHA3-384withRSA";
  93. algorithms["SHA3-384WITHRSAENCRYPTION"] = "SHA3-384withRSA";
  94. algorithms[NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_384.Id] = "SHA3-384withRSA";
  95. algorithms["SHA3-512WITHRSA"] = "SHA3-512withRSA";
  96. algorithms["SHA3-512WITHRSAENCRYPTION"] = "SHA3-512withRSA";
  97. algorithms[NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_512.Id] = "SHA3-512withRSA";
  98. algorithms["PSSWITHRSA"] = "PSSwithRSA";
  99. algorithms["RSASSA-PSS"] = "PSSwithRSA";
  100. algorithms[PkcsObjectIdentifiers.IdRsassaPss.Id] = "PSSwithRSA";
  101. algorithms["RSAPSS"] = "PSSwithRSA";
  102. algorithms["SHA1WITHRSAANDMGF1"] = "SHA-1withRSAandMGF1";
  103. algorithms["SHA-1WITHRSAANDMGF1"] = "SHA-1withRSAandMGF1";
  104. algorithms["SHA1WITHRSA/PSS"] = "SHA-1withRSAandMGF1";
  105. algorithms["SHA-1WITHRSA/PSS"] = "SHA-1withRSAandMGF1";
  106. algorithms["SHA1WITHRSASSA-PSS"] = "SHA-1withRSAandMGF1";
  107. algorithms["SHA-1WITHRSASSA-PSS"] = "SHA-1withRSAandMGF1";
  108. algorithms["SHA224WITHRSAANDMGF1"] = "SHA-224withRSAandMGF1";
  109. algorithms["SHA-224WITHRSAANDMGF1"] = "SHA-224withRSAandMGF1";
  110. algorithms["SHA224WITHRSA/PSS"] = "SHA-224withRSAandMGF1";
  111. algorithms["SHA-224WITHRSA/PSS"] = "SHA-224withRSAandMGF1";
  112. algorithms["SHA224WITHRSASSA-PSS"] = "SHA-224withRSAandMGF1";
  113. algorithms["SHA-224WITHRSASSA-PSS"] = "SHA-224withRSAandMGF1";
  114. algorithms["SHA256WITHRSAANDMGF1"] = "SHA-256withRSAandMGF1";
  115. algorithms["SHA-256WITHRSAANDMGF1"] = "SHA-256withRSAandMGF1";
  116. algorithms["SHA256WITHRSA/PSS"] = "SHA-256withRSAandMGF1";
  117. algorithms["SHA-256WITHRSA/PSS"] = "SHA-256withRSAandMGF1";
  118. algorithms["SHA256WITHRSASSA-PSS"] = "SHA-256withRSAandMGF1";
  119. algorithms["SHA-256WITHRSASSA-PSS"] = "SHA-256withRSAandMGF1";
  120. algorithms["SHA384WITHRSAANDMGF1"] = "SHA-384withRSAandMGF1";
  121. algorithms["SHA-384WITHRSAANDMGF1"] = "SHA-384withRSAandMGF1";
  122. algorithms["SHA384WITHRSA/PSS"] = "SHA-384withRSAandMGF1";
  123. algorithms["SHA-384WITHRSA/PSS"] = "SHA-384withRSAandMGF1";
  124. algorithms["SHA384WITHRSASSA-PSS"] = "SHA-384withRSAandMGF1";
  125. algorithms["SHA-384WITHRSASSA-PSS"] = "SHA-384withRSAandMGF1";
  126. algorithms["SHA512WITHRSAANDMGF1"] = "SHA-512withRSAandMGF1";
  127. algorithms["SHA-512WITHRSAANDMGF1"] = "SHA-512withRSAandMGF1";
  128. algorithms["SHA512WITHRSA/PSS"] = "SHA-512withRSAandMGF1";
  129. algorithms["SHA-512WITHRSA/PSS"] = "SHA-512withRSAandMGF1";
  130. algorithms["SHA512WITHRSASSA-PSS"] = "SHA-512withRSAandMGF1";
  131. algorithms["SHA-512WITHRSASSA-PSS"] = "SHA-512withRSAandMGF1";
  132. algorithms["RIPEMD128WITHRSA"] = "RIPEMD128withRSA";
  133. algorithms["RIPEMD128WITHRSAENCRYPTION"] = "RIPEMD128withRSA";
  134. algorithms[TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128.Id] = "RIPEMD128withRSA";
  135. algorithms["RIPEMD160WITHRSA"] = "RIPEMD160withRSA";
  136. algorithms["RIPEMD160WITHRSAENCRYPTION"] = "RIPEMD160withRSA";
  137. algorithms[TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160.Id] = "RIPEMD160withRSA";
  138. algorithms["RIPEMD256WITHRSA"] = "RIPEMD256withRSA";
  139. algorithms["RIPEMD256WITHRSAENCRYPTION"] = "RIPEMD256withRSA";
  140. algorithms[TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256.Id] = "RIPEMD256withRSA";
  141. algorithms["NONEWITHRSA"] = "RSA";
  142. algorithms["RSAWITHNONE"] = "RSA";
  143. algorithms["RAWRSA"] = "RSA";
  144. algorithms["RAWRSAPSS"] = "RAWRSASSA-PSS";
  145. algorithms["NONEWITHRSAPSS"] = "RAWRSASSA-PSS";
  146. algorithms["NONEWITHRSASSA-PSS"] = "RAWRSASSA-PSS";
  147. algorithms["NONEWITHDSA"] = "NONEwithDSA";
  148. algorithms["DSAWITHNONE"] = "NONEwithDSA";
  149. algorithms["RAWDSA"] = "NONEwithDSA";
  150. algorithms["DSA"] = "SHA-1withDSA";
  151. algorithms["DSAWITHSHA1"] = "SHA-1withDSA";
  152. algorithms["DSAWITHSHA-1"] = "SHA-1withDSA";
  153. algorithms["SHA/DSA"] = "SHA-1withDSA";
  154. algorithms["SHA1/DSA"] = "SHA-1withDSA";
  155. algorithms["SHA-1/DSA"] = "SHA-1withDSA";
  156. algorithms["SHA1WITHDSA"] = "SHA-1withDSA";
  157. algorithms["SHA-1WITHDSA"] = "SHA-1withDSA";
  158. algorithms[X9ObjectIdentifiers.IdDsaWithSha1.Id] = "SHA-1withDSA";
  159. algorithms[OiwObjectIdentifiers.DsaWithSha1.Id] = "SHA-1withDSA";
  160. algorithms["DSAWITHSHA224"] = "SHA-224withDSA";
  161. algorithms["DSAWITHSHA-224"] = "SHA-224withDSA";
  162. algorithms["SHA224/DSA"] = "SHA-224withDSA";
  163. algorithms["SHA-224/DSA"] = "SHA-224withDSA";
  164. algorithms["SHA224WITHDSA"] = "SHA-224withDSA";
  165. algorithms["SHA-224WITHDSA"] = "SHA-224withDSA";
  166. algorithms[NistObjectIdentifiers.DsaWithSha224.Id] = "SHA-224withDSA";
  167. algorithms["DSAWITHSHA256"] = "SHA-256withDSA";
  168. algorithms["DSAWITHSHA-256"] = "SHA-256withDSA";
  169. algorithms["SHA256/DSA"] = "SHA-256withDSA";
  170. algorithms["SHA-256/DSA"] = "SHA-256withDSA";
  171. algorithms["SHA256WITHDSA"] = "SHA-256withDSA";
  172. algorithms["SHA-256WITHDSA"] = "SHA-256withDSA";
  173. algorithms[NistObjectIdentifiers.DsaWithSha256.Id] = "SHA-256withDSA";
  174. algorithms["DSAWITHSHA384"] = "SHA-384withDSA";
  175. algorithms["DSAWITHSHA-384"] = "SHA-384withDSA";
  176. algorithms["SHA384/DSA"] = "SHA-384withDSA";
  177. algorithms["SHA-384/DSA"] = "SHA-384withDSA";
  178. algorithms["SHA384WITHDSA"] = "SHA-384withDSA";
  179. algorithms["SHA-384WITHDSA"] = "SHA-384withDSA";
  180. algorithms[NistObjectIdentifiers.DsaWithSha384.Id] = "SHA-384withDSA";
  181. algorithms["DSAWITHSHA512"] = "SHA-512withDSA";
  182. algorithms["DSAWITHSHA-512"] = "SHA-512withDSA";
  183. algorithms["SHA512/DSA"] = "SHA-512withDSA";
  184. algorithms["SHA-512/DSA"] = "SHA-512withDSA";
  185. algorithms["SHA512WITHDSA"] = "SHA-512withDSA";
  186. algorithms["SHA-512WITHDSA"] = "SHA-512withDSA";
  187. algorithms[NistObjectIdentifiers.DsaWithSha512.Id] = "SHA-512withDSA";
  188. algorithms["NONEWITHECDSA"] = "NONEwithECDSA";
  189. algorithms["ECDSAWITHNONE"] = "NONEwithECDSA";
  190. algorithms["ECDSA"] = "SHA-1withECDSA";
  191. algorithms["SHA1/ECDSA"] = "SHA-1withECDSA";
  192. algorithms["SHA-1/ECDSA"] = "SHA-1withECDSA";
  193. algorithms["ECDSAWITHSHA1"] = "SHA-1withECDSA";
  194. algorithms["ECDSAWITHSHA-1"] = "SHA-1withECDSA";
  195. algorithms["SHA1WITHECDSA"] = "SHA-1withECDSA";
  196. algorithms["SHA-1WITHECDSA"] = "SHA-1withECDSA";
  197. algorithms[X9ObjectIdentifiers.ECDsaWithSha1.Id] = "SHA-1withECDSA";
  198. algorithms[TeleTrusTObjectIdentifiers.ECSignWithSha1.Id] = "SHA-1withECDSA";
  199. algorithms["SHA224/ECDSA"] = "SHA-224withECDSA";
  200. algorithms["SHA-224/ECDSA"] = "SHA-224withECDSA";
  201. algorithms["ECDSAWITHSHA224"] = "SHA-224withECDSA";
  202. algorithms["ECDSAWITHSHA-224"] = "SHA-224withECDSA";
  203. algorithms["SHA224WITHECDSA"] = "SHA-224withECDSA";
  204. algorithms["SHA-224WITHECDSA"] = "SHA-224withECDSA";
  205. algorithms[X9ObjectIdentifiers.ECDsaWithSha224.Id] = "SHA-224withECDSA";
  206. algorithms["SHA256/ECDSA"] = "SHA-256withECDSA";
  207. algorithms["SHA-256/ECDSA"] = "SHA-256withECDSA";
  208. algorithms["ECDSAWITHSHA256"] = "SHA-256withECDSA";
  209. algorithms["ECDSAWITHSHA-256"] = "SHA-256withECDSA";
  210. algorithms["SHA256WITHECDSA"] = "SHA-256withECDSA";
  211. algorithms["SHA-256WITHECDSA"] = "SHA-256withECDSA";
  212. algorithms[X9ObjectIdentifiers.ECDsaWithSha256.Id] = "SHA-256withECDSA";
  213. algorithms["SHA384/ECDSA"] = "SHA-384withECDSA";
  214. algorithms["SHA-384/ECDSA"] = "SHA-384withECDSA";
  215. algorithms["ECDSAWITHSHA384"] = "SHA-384withECDSA";
  216. algorithms["ECDSAWITHSHA-384"] = "SHA-384withECDSA";
  217. algorithms["SHA384WITHECDSA"] = "SHA-384withECDSA";
  218. algorithms["SHA-384WITHECDSA"] = "SHA-384withECDSA";
  219. algorithms[X9ObjectIdentifiers.ECDsaWithSha384.Id] = "SHA-384withECDSA";
  220. algorithms["SHA512/ECDSA"] = "SHA-512withECDSA";
  221. algorithms["SHA-512/ECDSA"] = "SHA-512withECDSA";
  222. algorithms["ECDSAWITHSHA512"] = "SHA-512withECDSA";
  223. algorithms["ECDSAWITHSHA-512"] = "SHA-512withECDSA";
  224. algorithms["SHA512WITHECDSA"] = "SHA-512withECDSA";
  225. algorithms["SHA-512WITHECDSA"] = "SHA-512withECDSA";
  226. algorithms[X9ObjectIdentifiers.ECDsaWithSha512.Id] = "SHA-512withECDSA";
  227. algorithms["RIPEMD160/ECDSA"] = "RIPEMD160withECDSA";
  228. algorithms["ECDSAWITHRIPEMD160"] = "RIPEMD160withECDSA";
  229. algorithms["RIPEMD160WITHECDSA"] = "RIPEMD160withECDSA";
  230. algorithms[TeleTrusTObjectIdentifiers.ECSignWithRipeMD160.Id] = "RIPEMD160withECDSA";
  231. algorithms["NONEWITHCVC-ECDSA"] = "NONEwithCVC-ECDSA";
  232. algorithms["CVC-ECDSAWITHNONE"] = "NONEwithCVC-ECDSA";
  233. algorithms["SHA1/CVC-ECDSA"] = "SHA-1withCVC-ECDSA";
  234. algorithms["SHA-1/CVC-ECDSA"] = "SHA-1withCVC-ECDSA";
  235. algorithms["CVC-ECDSAWITHSHA1"] = "SHA-1withCVC-ECDSA";
  236. algorithms["CVC-ECDSAWITHSHA-1"] = "SHA-1withCVC-ECDSA";
  237. algorithms["SHA1WITHCVC-ECDSA"] = "SHA-1withCVC-ECDSA";
  238. algorithms["SHA-1WITHCVC-ECDSA"] = "SHA-1withCVC-ECDSA";
  239. algorithms[EacObjectIdentifiers.id_TA_ECDSA_SHA_1.Id] = "SHA-1withCVC-ECDSA";
  240. algorithms["SHA224/CVC-ECDSA"] = "SHA-224withCVC-ECDSA";
  241. algorithms["SHA-224/CVC-ECDSA"] = "SHA-224withCVC-ECDSA";
  242. algorithms["CVC-ECDSAWITHSHA224"] = "SHA-224withCVC-ECDSA";
  243. algorithms["CVC-ECDSAWITHSHA-224"] = "SHA-224withCVC-ECDSA";
  244. algorithms["SHA224WITHCVC-ECDSA"] = "SHA-224withCVC-ECDSA";
  245. algorithms["SHA-224WITHCVC-ECDSA"] = "SHA-224withCVC-ECDSA";
  246. algorithms[EacObjectIdentifiers.id_TA_ECDSA_SHA_224.Id] = "SHA-224withCVC-ECDSA";
  247. algorithms["SHA256/CVC-ECDSA"] = "SHA-256withCVC-ECDSA";
  248. algorithms["SHA-256/CVC-ECDSA"] = "SHA-256withCVC-ECDSA";
  249. algorithms["CVC-ECDSAWITHSHA256"] = "SHA-256withCVC-ECDSA";
  250. algorithms["CVC-ECDSAWITHSHA-256"] = "SHA-256withCVC-ECDSA";
  251. algorithms["SHA256WITHCVC-ECDSA"] = "SHA-256withCVC-ECDSA";
  252. algorithms["SHA-256WITHCVC-ECDSA"] = "SHA-256withCVC-ECDSA";
  253. algorithms[EacObjectIdentifiers.id_TA_ECDSA_SHA_256.Id] = "SHA-256withCVC-ECDSA";
  254. algorithms["SHA384/CVC-ECDSA"] = "SHA-384withCVC-ECDSA";
  255. algorithms["SHA-384/CVC-ECDSA"] = "SHA-384withCVC-ECDSA";
  256. algorithms["CVC-ECDSAWITHSHA384"] = "SHA-384withCVC-ECDSA";
  257. algorithms["CVC-ECDSAWITHSHA-384"] = "SHA-384withCVC-ECDSA";
  258. algorithms["SHA384WITHCVC-ECDSA"] = "SHA-384withCVC-ECDSA";
  259. algorithms["SHA-384WITHCVC-ECDSA"] = "SHA-384withCVC-ECDSA";
  260. algorithms[EacObjectIdentifiers.id_TA_ECDSA_SHA_384.Id] = "SHA-384withCVC-ECDSA";
  261. algorithms["SHA512/CVC-ECDSA"] = "SHA-512withCVC-ECDSA";
  262. algorithms["SHA-512/CVC-ECDSA"] = "SHA-512withCVC-ECDSA";
  263. algorithms["CVC-ECDSAWITHSHA512"] = "SHA-512withCVC-ECDSA";
  264. algorithms["CVC-ECDSAWITHSHA-512"] = "SHA-512withCVC-ECDSA";
  265. algorithms["SHA512WITHCVC-ECDSA"] = "SHA-512withCVC-ECDSA";
  266. algorithms["SHA-512WITHCVC-ECDSA"] = "SHA-512withCVC-ECDSA";
  267. algorithms[EacObjectIdentifiers.id_TA_ECDSA_SHA_512.Id] = "SHA-512withCVC-ECDSA";
  268. algorithms["NONEWITHPLAIN-ECDSA"] = "NONEwithPLAIN-ECDSA";
  269. algorithms["PLAIN-ECDSAWITHNONE"] = "NONEwithPLAIN-ECDSA";
  270. algorithms["SHA1/PLAIN-ECDSA"] = "SHA-1withPLAIN-ECDSA";
  271. algorithms["SHA-1/PLAIN-ECDSA"] = "SHA-1withPLAIN-ECDSA";
  272. algorithms["PLAIN-ECDSAWITHSHA1"] = "SHA-1withPLAIN-ECDSA";
  273. algorithms["PLAIN-ECDSAWITHSHA-1"] = "SHA-1withPLAIN-ECDSA";
  274. algorithms["SHA1WITHPLAIN-ECDSA"] = "SHA-1withPLAIN-ECDSA";
  275. algorithms["SHA-1WITHPLAIN-ECDSA"] = "SHA-1withPLAIN-ECDSA";
  276. algorithms[BsiObjectIdentifiers.ecdsa_plain_SHA1.Id] = "SHA-1withPLAIN-ECDSA";
  277. algorithms["SHA224/PLAIN-ECDSA"] = "SHA-224withPLAIN-ECDSA";
  278. algorithms["SHA-224/PLAIN-ECDSA"] = "SHA-224withPLAIN-ECDSA";
  279. algorithms["PLAIN-ECDSAWITHSHA224"] = "SHA-224withPLAIN-ECDSA";
  280. algorithms["PLAIN-ECDSAWITHSHA-224"] = "SHA-224withPLAIN-ECDSA";
  281. algorithms["SHA224WITHPLAIN-ECDSA"] = "SHA-224withPLAIN-ECDSA";
  282. algorithms["SHA-224WITHPLAIN-ECDSA"] = "SHA-224withPLAIN-ECDSA";
  283. algorithms[BsiObjectIdentifiers.ecdsa_plain_SHA224.Id] = "SHA-224withPLAIN-ECDSA";
  284. algorithms["SHA256/PLAIN-ECDSA"] = "SHA-256withPLAIN-ECDSA";
  285. algorithms["SHA-256/PLAIN-ECDSA"] = "SHA-256withPLAIN-ECDSA";
  286. algorithms["PLAIN-ECDSAWITHSHA256"] = "SHA-256withPLAIN-ECDSA";
  287. algorithms["PLAIN-ECDSAWITHSHA-256"] = "SHA-256withPLAIN-ECDSA";
  288. algorithms["SHA256WITHPLAIN-ECDSA"] = "SHA-256withPLAIN-ECDSA";
  289. algorithms["SHA-256WITHPLAIN-ECDSA"] = "SHA-256withPLAIN-ECDSA";
  290. algorithms[BsiObjectIdentifiers.ecdsa_plain_SHA256.Id] = "SHA-256withPLAIN-ECDSA";
  291. algorithms["SHA384/PLAIN-ECDSA"] = "SHA-384withPLAIN-ECDSA";
  292. algorithms["SHA-384/PLAIN-ECDSA"] = "SHA-384withPLAIN-ECDSA";
  293. algorithms["PLAIN-ECDSAWITHSHA384"] = "SHA-384withPLAIN-ECDSA";
  294. algorithms["PLAIN-ECDSAWITHSHA-384"] = "SHA-384withPLAIN-ECDSA";
  295. algorithms["SHA384WITHPLAIN-ECDSA"] = "SHA-384withPLAIN-ECDSA";
  296. algorithms["SHA-384WITHPLAIN-ECDSA"] = "SHA-384withPLAIN-ECDSA";
  297. algorithms[BsiObjectIdentifiers.ecdsa_plain_SHA384.Id] = "SHA-384withPLAIN-ECDSA";
  298. algorithms["SHA512/PLAIN-ECDSA"] = "SHA-512withPLAIN-ECDSA";
  299. algorithms["SHA-512/PLAIN-ECDSA"] = "SHA-512withPLAIN-ECDSA";
  300. algorithms["PLAIN-ECDSAWITHSHA512"] = "SHA-512withPLAIN-ECDSA";
  301. algorithms["PLAIN-ECDSAWITHSHA-512"] = "SHA-512withPLAIN-ECDSA";
  302. algorithms["SHA512WITHPLAIN-ECDSA"] = "SHA-512withPLAIN-ECDSA";
  303. algorithms["SHA-512WITHPLAIN-ECDSA"] = "SHA-512withPLAIN-ECDSA";
  304. algorithms[BsiObjectIdentifiers.ecdsa_plain_SHA512.Id] = "SHA-512withPLAIN-ECDSA";
  305. algorithms["RIPEMD160/PLAIN-ECDSA"] = "RIPEMD160withPLAIN-ECDSA";
  306. algorithms["PLAIN-ECDSAWITHRIPEMD160"] = "RIPEMD160withPLAIN-ECDSA";
  307. algorithms["RIPEMD160WITHPLAIN-ECDSA"] = "RIPEMD160withPLAIN-ECDSA";
  308. algorithms[BsiObjectIdentifiers.ecdsa_plain_RIPEMD160.Id] = "RIPEMD160withPLAIN-ECDSA";
  309. algorithms["SHA1WITHECNR"] = "SHA-1withECNR";
  310. algorithms["SHA-1WITHECNR"] = "SHA-1withECNR";
  311. algorithms["SHA224WITHECNR"] = "SHA-224withECNR";
  312. algorithms["SHA-224WITHECNR"] = "SHA-224withECNR";
  313. algorithms["SHA256WITHECNR"] = "SHA-256withECNR";
  314. algorithms["SHA-256WITHECNR"] = "SHA-256withECNR";
  315. algorithms["SHA384WITHECNR"] = "SHA-384withECNR";
  316. algorithms["SHA-384WITHECNR"] = "SHA-384withECNR";
  317. algorithms["SHA512WITHECNR"] = "SHA-512withECNR";
  318. algorithms["SHA-512WITHECNR"] = "SHA-512withECNR";
  319. algorithms["GOST-3410"] = "GOST3410";
  320. algorithms["GOST-3410-94"] = "GOST3410";
  321. algorithms["GOST3411WITHGOST3410"] = "GOST3410";
  322. algorithms[CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94.Id] = "GOST3410";
  323. algorithms["ECGOST-3410"] = "ECGOST3410";
  324. algorithms["ECGOST-3410-2001"] = "ECGOST3410";
  325. algorithms["GOST3411WITHECGOST3410"] = "ECGOST3410";
  326. algorithms[CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001.Id] = "ECGOST3410";
  327. algorithms["ED25519"] = "Ed25519";
  328. algorithms[EdECObjectIdentifiers.id_Ed25519.Id] = "Ed25519";
  329. algorithms["ED25519CTX"] = "Ed25519ctx";
  330. algorithms["ED25519PH"] = "Ed25519ph";
  331. algorithms["ED448"] = "Ed448";
  332. algorithms[EdECObjectIdentifiers.id_Ed448.Id] = "Ed448";
  333. algorithms["ED448PH"] = "Ed448ph";
  334. algorithms["SHA256WITHSM2"] = "SHA256withSM2";
  335. algorithms[GMObjectIdentifiers.sm2sign_with_sha256.Id] = "SHA256withSM2";
  336. algorithms["SM3WITHSM2"] = "SM3withSM2";
  337. algorithms[GMObjectIdentifiers.sm2sign_with_sm3.Id] = "SM3withSM2";
  338. oids["MD2withRSA"] = PkcsObjectIdentifiers.MD2WithRsaEncryption;
  339. oids["MD4withRSA"] = PkcsObjectIdentifiers.MD4WithRsaEncryption;
  340. oids["MD5withRSA"] = PkcsObjectIdentifiers.MD5WithRsaEncryption;
  341. oids["SHA-1withRSA"] = PkcsObjectIdentifiers.Sha1WithRsaEncryption;
  342. oids["SHA-224withRSA"] = PkcsObjectIdentifiers.Sha224WithRsaEncryption;
  343. oids["SHA-256withRSA"] = PkcsObjectIdentifiers.Sha256WithRsaEncryption;
  344. oids["SHA-384withRSA"] = PkcsObjectIdentifiers.Sha384WithRsaEncryption;
  345. oids["SHA-512withRSA"] = PkcsObjectIdentifiers.Sha512WithRsaEncryption;
  346. oids["SHA-512(224)withRSA"] = PkcsObjectIdentifiers.Sha512_224WithRSAEncryption;
  347. oids["SHA-512(256)withRSA"] = PkcsObjectIdentifiers.Sha512_256WithRSAEncryption;
  348. oids["SHA3-224withRSA"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_224;
  349. oids["SHA3-256withRSA"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_256;
  350. oids["SHA3-384withRSA"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_384;
  351. oids["SHA3-512withRSA"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_512;
  352. oids["PSSwithRSA"] = PkcsObjectIdentifiers.IdRsassaPss;
  353. oids["SHA-1withRSAandMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
  354. oids["SHA-224withRSAandMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
  355. oids["SHA-256withRSAandMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
  356. oids["SHA-384withRSAandMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
  357. oids["SHA-512withRSAandMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
  358. oids["RIPEMD128withRSA"] = TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128;
  359. oids["RIPEMD160withRSA"] = TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160;
  360. oids["RIPEMD256withRSA"] = TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256;
  361. oids["SHA-1withDSA"] = X9ObjectIdentifiers.IdDsaWithSha1;
  362. oids["SHA-1withECDSA"] = X9ObjectIdentifiers.ECDsaWithSha1;
  363. oids["SHA-224withECDSA"] = X9ObjectIdentifiers.ECDsaWithSha224;
  364. oids["SHA-256withECDSA"] = X9ObjectIdentifiers.ECDsaWithSha256;
  365. oids["SHA-384withECDSA"] = X9ObjectIdentifiers.ECDsaWithSha384;
  366. oids["SHA-512withECDSA"] = X9ObjectIdentifiers.ECDsaWithSha512;
  367. oids["RIPEMD160withECDSA"] = TeleTrusTObjectIdentifiers.ECSignWithRipeMD160;
  368. oids["SHA-1withCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_1;
  369. oids["SHA-224withCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_224;
  370. oids["SHA-256withCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_256;
  371. oids["SHA-384withCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_384;
  372. oids["SHA-512withCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_512;
  373. oids["SHA-1withPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA1;
  374. oids["SHA-224withPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA224;
  375. oids["SHA-256withPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA256;
  376. oids["SHA-384withPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA384;
  377. oids["SHA-512withPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA512;
  378. oids["RIPEMD160withPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_RIPEMD160;
  379. oids["GOST3410"] = CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94;
  380. oids["ECGOST3410"] = CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001;
  381. oids["Ed25519"] = EdECObjectIdentifiers.id_Ed25519;
  382. oids["Ed448"] = EdECObjectIdentifiers.id_Ed448;
  383. oids["SHA256withSM2"] = GMObjectIdentifiers.sm2sign_with_sha256;
  384. oids["SM3withSM2"] = GMObjectIdentifiers.sm2sign_with_sm3;
  385. }
  386. /// <summary>
  387. /// Returns an ObjectIdentifier for a given encoding.
  388. /// </summary>
  389. /// <param name="mechanism">A string representation of the encoding.</param>
  390. /// <returns>A DerObjectIdentifier, null if the OID is not available.</returns>
  391. // TODO Don't really want to support this
  392. public static DerObjectIdentifier GetObjectIdentifier(
  393. string mechanism)
  394. {
  395. if (mechanism == null)
  396. throw new ArgumentNullException("mechanism");
  397. mechanism = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.ToUpperInvariant(mechanism);
  398. string aliased = (string) algorithms[mechanism];
  399. if (aliased != null)
  400. mechanism = aliased;
  401. return (DerObjectIdentifier) oids[mechanism];
  402. }
  403. public static ICollection Algorithms
  404. {
  405. get { return oids.Keys; }
  406. }
  407. public static Asn1Encodable GetDefaultX509Parameters(
  408. DerObjectIdentifier id)
  409. {
  410. return GetDefaultX509Parameters(id.Id);
  411. }
  412. public static Asn1Encodable GetDefaultX509Parameters(
  413. string algorithm)
  414. {
  415. if (algorithm == null)
  416. throw new ArgumentNullException("algorithm");
  417. algorithm = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.ToUpperInvariant(algorithm);
  418. string mechanism = (string) algorithms[algorithm];
  419. if (mechanism == null)
  420. mechanism = algorithm;
  421. if (mechanism == "PSSwithRSA")
  422. {
  423. // TODO The Sha1Digest here is a default. In JCE version, the actual digest
  424. // to be used can be overridden by subsequent parameter settings.
  425. return GetPssX509Parameters("SHA-1");
  426. }
  427. if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "withRSAandMGF1"))
  428. {
  429. string digestName = mechanism.Substring(0, mechanism.Length - "withRSAandMGF1".Length);
  430. return GetPssX509Parameters(digestName);
  431. }
  432. return DerNull.Instance;
  433. }
  434. private static Asn1Encodable GetPssX509Parameters(
  435. string digestName)
  436. {
  437. AlgorithmIdentifier hashAlgorithm = new AlgorithmIdentifier(
  438. DigestUtilities.GetObjectIdentifier(digestName), DerNull.Instance);
  439. // TODO Is it possible for the MGF hash alg to be different from the PSS one?
  440. AlgorithmIdentifier maskGenAlgorithm = new AlgorithmIdentifier(
  441. PkcsObjectIdentifiers.IdMgf1, hashAlgorithm);
  442. int saltLen = DigestUtilities.GetDigest(digestName).GetDigestSize();
  443. return new RsassaPssParameters(hashAlgorithm, maskGenAlgorithm,
  444. new DerInteger(saltLen), new DerInteger(1));
  445. }
  446. public static ISigner GetSigner(
  447. DerObjectIdentifier id)
  448. {
  449. return GetSigner(id.Id);
  450. }
  451. public static ISigner GetSigner(
  452. string algorithm)
  453. {
  454. if (algorithm == null)
  455. throw new ArgumentNullException("algorithm");
  456. algorithm = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.ToUpperInvariant(algorithm);
  457. string mechanism = (string) algorithms[algorithm];
  458. if (mechanism == null)
  459. mechanism = algorithm;
  460. if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "Ed"))
  461. {
  462. if (mechanism.Equals("Ed25519"))
  463. {
  464. return new Ed25519Signer();
  465. }
  466. if (mechanism.Equals("Ed25519ctx"))
  467. {
  468. return new Ed25519ctxSigner(Arrays.EmptyBytes);
  469. }
  470. if (mechanism.Equals("Ed25519ph"))
  471. {
  472. return new Ed25519phSigner(Arrays.EmptyBytes);
  473. }
  474. if (mechanism.Equals("Ed448"))
  475. {
  476. return new Ed448Signer(Arrays.EmptyBytes);
  477. }
  478. if (mechanism.Equals("Ed448ph"))
  479. {
  480. return new Ed448phSigner(Arrays.EmptyBytes);
  481. }
  482. }
  483. if (mechanism.Equals("RSA"))
  484. {
  485. return (new RsaDigestSigner(new NullDigest(), (AlgorithmIdentifier)null));
  486. }
  487. if (mechanism.Equals("RAWRSASSA-PSS"))
  488. {
  489. // TODO Add support for other parameter settings
  490. return PssSigner.CreateRawSigner(new RsaBlindedEngine(), new Sha1Digest());
  491. }
  492. if (mechanism.Equals("PSSwithRSA"))
  493. {
  494. // TODO The Sha1Digest here is a default. In JCE version, the actual digest
  495. // to be used can be overridden by subsequent parameter settings.
  496. return new PssSigner(new RsaBlindedEngine(), new Sha1Digest());
  497. }
  498. if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "withRSA"))
  499. {
  500. string digestName = mechanism.Substring(0, mechanism.LastIndexOf("with"));
  501. IDigest digest = DigestUtilities.GetDigest(digestName);
  502. return new RsaDigestSigner(digest);
  503. }
  504. if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "withRSAandMGF1"))
  505. {
  506. string digestName = mechanism.Substring(0, mechanism.LastIndexOf("with"));
  507. IDigest digest = DigestUtilities.GetDigest(digestName);
  508. return new PssSigner(new RsaBlindedEngine(), digest);
  509. }
  510. if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "withDSA"))
  511. {
  512. string digestName = mechanism.Substring(0, mechanism.LastIndexOf("with"));
  513. IDigest digest = DigestUtilities.GetDigest(digestName);
  514. return new DsaDigestSigner(new DsaSigner(), digest);
  515. }
  516. if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "withECDSA"))
  517. {
  518. string digestName = mechanism.Substring(0, mechanism.LastIndexOf("with"));
  519. IDigest digest = DigestUtilities.GetDigest(digestName);
  520. return new DsaDigestSigner(new ECDsaSigner(), digest);
  521. }
  522. if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "withCVC-ECDSA")
  523. || BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "withPLAIN-ECDSA"))
  524. {
  525. string digestName = mechanism.Substring(0, mechanism.LastIndexOf("with"));
  526. IDigest digest = DigestUtilities.GetDigest(digestName);
  527. return new DsaDigestSigner(new ECDsaSigner(), digest, PlainDsaEncoding.Instance);
  528. }
  529. if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "withECNR"))
  530. {
  531. string digestName = mechanism.Substring(0, mechanism.LastIndexOf("with"));
  532. IDigest digest = DigestUtilities.GetDigest(digestName);
  533. return new DsaDigestSigner(new ECNRSigner(), digest);
  534. }
  535. if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "withSM2"))
  536. {
  537. string digestName = mechanism.Substring(0, mechanism.LastIndexOf("with"));
  538. IDigest digest = DigestUtilities.GetDigest(digestName);
  539. return new SM2Signer(digest);
  540. }
  541. if (mechanism.Equals("GOST3410"))
  542. {
  543. return new Gost3410DigestSigner(new Gost3410Signer(), new Gost3411Digest());
  544. }
  545. if (mechanism.Equals("ECGOST3410"))
  546. {
  547. return new Gost3410DigestSigner(new ECGost3410Signer(), new Gost3411Digest());
  548. }
  549. if (mechanism.Equals("SHA1WITHRSA/ISO9796-2"))
  550. {
  551. return new Iso9796d2Signer(new RsaBlindedEngine(), new Sha1Digest(), true);
  552. }
  553. if (mechanism.Equals("MD5WITHRSA/ISO9796-2"))
  554. {
  555. return new Iso9796d2Signer(new RsaBlindedEngine(), new MD5Digest(), true);
  556. }
  557. if (mechanism.Equals("RIPEMD160WITHRSA/ISO9796-2"))
  558. {
  559. return new Iso9796d2Signer(new RsaBlindedEngine(), new RipeMD160Digest(), true);
  560. }
  561. if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.EndsWith(mechanism, "/X9.31"))
  562. {
  563. string x931 = mechanism.Substring(0, mechanism.Length - "/X9.31".Length);
  564. int withPos = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.IndexOf(x931, "WITH");
  565. if (withPos > 0)
  566. {
  567. int endPos = withPos + "WITH".Length;
  568. string digestName = x931.Substring(0, withPos);
  569. IDigest digest = DigestUtilities.GetDigest(digestName);
  570. string cipherName = x931.Substring(endPos, x931.Length - endPos);
  571. if (cipherName.Equals("RSA"))
  572. {
  573. IAsymmetricBlockCipher cipher = new RsaBlindedEngine();
  574. return new X931Signer(cipher, digest);
  575. }
  576. }
  577. }
  578. throw new SecurityUtilityException("Signer " + algorithm + " not recognised.");
  579. }
  580. public static string GetEncodingName(
  581. DerObjectIdentifier oid)
  582. {
  583. return (string) algorithms[oid.Id];
  584. }
  585. public static ISigner InitSigner(DerObjectIdentifier algorithmOid, bool forSigning, AsymmetricKeyParameter privateKey, SecureRandom random)
  586. {
  587. return InitSigner(algorithmOid.Id, forSigning, privateKey, random);
  588. }
  589. public static ISigner InitSigner(string algorithm, bool forSigning, AsymmetricKeyParameter privateKey, SecureRandom random)
  590. {
  591. ISigner signer = SignerUtilities.GetSigner(algorithm);
  592. signer.Init(forSigning, ParameterUtilities.WithRandom(privateKey, random));
  593. return signer;
  594. }
  595. }
  596. }
  597. #pragma warning restore
  598. #endif