File tree Expand file tree Collapse file tree 2 files changed +28
-13
lines changed
Expand file tree Collapse file tree 2 files changed +28
-13
lines changed Original file line number Diff line number Diff line change @@ -94,5 +94,30 @@ public void TestSamlRequest()
9494 Assert . IsTrue ( str . EndsWith ( @"ProtocolBinding=""urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"" AssertionConsumerServiceURL=""http://www.myapp.com/SamlConsume"" xmlns:samlp=""urn:oasis:names:tc:SAML:2.0:protocol""><saml:Issuer xmlns:saml=""urn:oasis:names:tc:SAML:2.0:assertion"">http://www.myapp.com</saml:Issuer><samlp:NameIDPolicy Format=""urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"" AllowCreate=""true"" /></samlp:AuthnRequest>" ) ) ;
9595
9696 }
97- }
97+
98+ [ TestMethod ]
99+ public void TestStringToByteArray ( )
100+ {
101+ //test that the old StringToByteArray was generating same result as the new Encoding.ASCII.GetBytes
102+
103+ var cert = @"-----BEGIN CERTIFICATE-----
104+ MIICajCCAdOgAwIBAgIBADANBgkqhkiG9w0BAQ0FADBSMQswCQYDVQQGEwJ1czETMBEGA1UECAwKQ2FsaWZvcm5pYTEVMBMGA1UECgwMT25lbG9naW4gSW5jMRcwFQYDVQQDDA5zcC5leGFtcGxlLmNvbTAeFw0xNDA3MTcxNDEyNTZaFw0xNTA3MTcxNDEyNTZaMFIxCzAJBgNVBAYTAnVzMRMwEQYDVQQIDApDYWxpZm9ybmlhMRUwEwYDVQQKDAxPbmVsb2dpbiBJbmMxFzAVBgNVBAMMDnNwLmV4YW1wbGUuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDZx+ON4IUoIWxgukTb1tOiX3bMYzYQiwWPUNMp+Fq82xoNogso2bykZG0yiJm5o8zv/sd6pGouayMgkx/2FSOdc36T0jGbCHuRSbtia0PEzNIRtmViMrt3AeoWBidRXmZsxCNLwgIV6dn2WpuE5Az0bHgpZnQxTKFek0BMKU/d8wIDAQABo1AwTjAdBgNVHQ4EFgQUGHxYqZYyX7cTxKVODVgZwSTdCnwwHwYDVR0jBBgwFoAUGHxYqZYyX7cTxKVODVgZwSTdCnwwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQ0FAAOBgQByFOl+hMFICbd3DJfnp2Rgd/dqttsZG/tyhILWvErbio/DEe98mXpowhTkC04ENprOyXi7ZbUqiicF89uAGyt1oqgTUCD1VsLahqIcmrzgumNyTwLGWo17WDAa1/usDhetWAMhgzF/Cnf5ek0nK00m0YZGyc4LzgD0CROMASTWNg==
105+ -----END CERTIFICATE-----" ;
106+
107+
108+ var x = StringToByteArray ( cert ) ;
109+ var y = Encoding . ASCII . GetBytes ( cert ) ;
110+ Assert . IsTrue ( x . SequenceEqual ( y ) ) ;
111+ }
112+
113+ private static byte [ ] StringToByteArray ( string st )
114+ {
115+ byte [ ] bytes = new byte [ st . Length ] ;
116+ for ( int i = 0 ; i < st . Length ; i ++ )
117+ {
118+ bytes [ i ] = ( byte ) st [ i ] ;
119+ }
120+ return bytes ;
121+ }
122+ }
98123}
Original file line number Diff line number Diff line change @@ -16,31 +16,21 @@ namespace Saml
1616{
1717 public class Response
1818 {
19- private static byte [ ] StringToByteArray ( string st )
20- {
21- byte [ ] bytes = new byte [ st . Length ] ;
22- for ( int i = 0 ; i < st . Length ; i ++ )
23- {
24- bytes [ i ] = ( byte ) st [ i ] ;
25- }
26- return bytes ;
27- }
28-
2919 protected XmlDocument _xmlDoc ;
3020 protected readonly X509Certificate2 _certificate ;
3121 protected XmlNamespaceManager _xmlNameSpaceManager ; //we need this one to run our XPath queries on the SAML XML
3222
3323 public string Xml { get { return _xmlDoc . OuterXml ; } }
3424
3525 public Response ( string certificateStr , string responseString )
36- : this ( StringToByteArray ( certificateStr ) , responseString ) { }
26+ : this ( Encoding . ASCII . GetBytes ( certificateStr ) , responseString ) { }
3727
3828 public Response ( byte [ ] certificateBytes , string responseString ) : this ( certificateBytes )
3929 {
4030 LoadXmlFromBase64 ( responseString ) ;
4131 }
4232
43- public Response ( string certificateStr ) : this ( StringToByteArray ( certificateStr ) ) { }
33+ public Response ( string certificateStr ) : this ( Encoding . ASCII . GetBytes ( certificateStr ) ) { }
4434
4535 public Response ( byte [ ] certificateBytes )
4636 {
You can’t perform that action at this time.
0 commit comments