public void SignWithCertificateTest()
        {
            const string Message = "This is a test message";

            string[] certs = { "valid_cert.pfx", "valid_cert2.pfx" };
            for (int i = 0; i < 2; i++)
            {
                X509Certificate2           x509Certificate = new X509Certificate2(certs[i], "password");
                ClientAssertionCertificate cac             = new ClientAssertionCertificate("some_id", x509Certificate);
                byte[] signature = cac.Sign(Message);
                Assert.IsNotNull(signature);

                GC.WaitForPendingFinalizers();

                signature = cac.Sign(Message);
                Assert.IsNotNull(signature);
            }
        }
예제 #2
0
        public string Sign(ClientAssertionCertificate credential, bool sendCertificate)
        {
            // Base64Url encoded header and claims
            string token = Encode(credential, sendCertificate);

            // Length check before sign
            if (MaxTokenLength < token.Length)
            {
                throw new MsalException(MsalError.EncodedTokenTooLong);
            }

            return(string.Concat(token, ".", UrlEncodeSegment(credential.Sign(token))));
        }