/// <summary> /// BouncyCastle加签/验签 /// </summary> public static void BouncyCastleSignVerify() { //string publicKeyJava = @"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiRpgGZSOYKG36k6f56D0bHHOQZubt344qgRAVrSmw0udQCV8YsN/qpjlVAeT3gpQ1kKf7YvuR3KylXu0/ckvwya7AYsfEGiRahZcH6uElfyLKcR/6PioMvNLDB2mxgfvZXRRqfxOss8Byb6SP1/xSHPwcJQUc/u5wiczEEWKwNyVRTkjKSIKp5iA+bjN9WGdscdBkNYxZTbbKwDJvzyouiniKR5kSa/6LUMmVDlqz1ZgGfj0WK+6He1o/QoR9s7o143+JjNEzLaLkaolyOBWiBaSYYcQzpdlbi4OOvpHVpVrZ00aJDo9Q2/Dui7orKoKRcCqVDizJd80n47Tf6uVEQIDAQAB"; string publicKeyJava = @"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCcym0uL9DaH/ybE6mYncjie2px Lcsd8pvCBFMZpDOrYyQWrbAw2lm4kQT+JP/tpmQYIab3erVAD3otj4ZGf7NL22Kj U8/6Xz9qICCwilx9RQG5QrZRvxYFxN2a0DaWiHITzWS7dejNoz6g5xFXL7U4IFTm j1wZXCv6tqQGJB84FQIDAQAB"; //string privateKeyJava = @"MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCJGmAZlI5gobfqTp /noPRscc5Bm5u3fjiqBEBWtKbDS51AJXxiw3+qmOVUB5PeClDWQp/ti+5HcrKVe7T9yS/DJrsBix8QaJFqFlwfq4SV/IspxH/o+Kgy80sMHabGB+9ldFGp/E6yzwHJvpI/X/FIc/BwlBRz+7nCJzMQRYrA3JVFOSMpIgqnmID5uM31YZ2xx0GQ1jFlNtsrAMm/PKi6KeIpHmRJr/otQyZUOWrPVmAZ+PRYr7od7Wj9ChH2zujXjf4mM0TMtouRqiXI4FaIFpJhhxDOl2VuLg46+kdWlWtnTRokOj1Db8O6LuisqgpFwKpUOLM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ZfGFG0fP03O1zwUddUq7Z/y1MLA3fs+vDFTeM3WKGYy7C1e8/vPtNmyaD/UYBpS6FxKVBNx4+mItbJzlHE42eNR5qX0GXwWJfyBTs3DCW9NIAiOT+0dXRma2leS8mPsKzidbtnKVj+tFW2+0cPqWRgzTVAgd1Srm86S/92w=="; string privateKeyJava = @"MIICWwIBAAKBgQCcym0uL9DaH/ybE6mYncjie2pxLcsd8pvCBFMZpDOrYyQWrbAw 2lm4kQT+JP/tpmQYIab3erVAD3otj4ZGf7NL22KjU8/6Xz9qICCwilx9RQG5QrZR vxYFxN2a0DaWiHITzWS7dejNoz6g5xFXL7U4IFTmj1wZXCv6tqQGJB84FQIDAQAB AoGAOqPe57pMc3gpItrcwE6q9kHQUpoc8ItvQ8YYSmvGQ2Bl+/FkBzFzAvuCEYdH DNwBbaEQcFi9d0MSn/2g67cRGEUCVlo4ve75Gu3pxOy7hhZ0dwOW1FaC6jeEyOJe B4AHRqXUSj+zKhMjZM399BrqFSc0kvkC3dtssbvGHcXMnwECQQDNNTSBFPUFe+O7 AWjzzgdQmB+tsqP87pQ9nnfHHA9xXReEOKpLl2dJwrVkpVwyniFkZq5Phwx2gYfx lD1xKv9BAkEAw5lRksTLjg7UTyk2vyYVGDhe/98dMgfaMkrx9M0C9XbSDvd9W5mq jC+qstgT66geFXjoWCtKTnfwJgnYjeoX1QJAaZrq9U8StYrHbNLR7z5lN03CZ8Ka cC1brsZhv98p915AHvSGdzZommYQscYDx6znZGMPa7AFcutAScvPPvEwwQJAM3Nm ALxhavm9oSEPNJK448kYPCgdTua/35DVOnae+6CIusUhJXIzaXK0bRzniIqNd0p5 m4+vmRp1ghv+6b2VDQJASaygxkO0W0CqwMDY7LwLqBW3guJENRcm6ZLbd9VfvS+I 3HMk8Qa9Yc9Iohi5UhtnjOZl5/FGZbC/HPcR6HgZRA=="; var algorithms = GetAlgorithms(); //string data = "helo world!"; //待签内容 string data = "eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0ZXIiLCJleHAiOjE1NTIzOTQ0MDc3NjcuMTM2MiwiZGF0YXMiOiJlMjk5M2VkMDI1MmM0ZGE0ZTMwZTYwMjY1YTM0ODM3NyJ9"; //int bbc = 0; foreach (var item in algorithms.Keys) { if (!item.ToString().Contains("RSA")) { continue; } if (item.ToString() == "SHA-512WITHRSA/PSS") { //注意SHA-512WITHRSA/PSS 对应的公私钥大小,不满足需求会报错的 key is too small } string signResult = RSAHelper.RSASignJavaBouncyCastle(data, privateKeyJava, item.ToString()); // bool result = RSAHelper.VerifyJavaBouncyCastle(data, publicKeyJava, signResult, item.ToString()); Console.WriteLine(item.ToString() + "加签: " + signResult); //Console.WriteLine(item.ToString() + "验证结果: "+result); Console.WriteLine(); //if (!result) //{ // int a = 0; // int b = 0 / a; //} } }
public Command() { this.converter = new RSAHelper(); }
public RSADecryptor(PrivateKey privateKey, RSAHelper converter) { this.privateKey = privateKey; this.converter = converter; }
public RSAEncryptor(PublicKey key, RSAHelper converter) { this.key = key; this.converter = converter; }