Пример #1
0
        private static ProofKeyOutput GetProofData(ProofKeyInput proofData)
        {
            if (proofData.AccessToken == null)
            {
                throw new ProofKeySigningException(nameof(proofData.AccessToken));
            }

            // Get the final values we'll operate on
            string accessToken = proofData.AccessToken;
            string hostUrl     = proofData.Url.ToUpperInvariant();
            long   timeStamp   = proofData.Timestamp;

            // Encode values from headers into byte[]
            byte[] accessTokenBytes = Encoding.UTF8.GetBytes(accessToken);
            byte[] hostUrlBytes     = Encoding.UTF8.GetBytes(hostUrl);
            byte[] timeStampBytes   = EncodeNumber(timeStamp);

            int accessTokenLength = accessTokenBytes.Length;
            int hostUrlLength     = hostUrlBytes.Length;
            int timeStampLength   = timeStampBytes.Length;

            byte[] accessTokenLengthBytes = EncodeNumber(accessTokenLength);
            byte[] hostUrlLengthBytes     = EncodeNumber(hostUrlLength);
            byte[] timeStampLengthBytes   = EncodeNumber(timeStampLength);

            // prepare a list that will be used to combine all those arrays together
            List <byte> expectedProof = new List <byte>(
                accessTokenLengthBytes.Length + accessTokenLength +
                hostUrlLengthBytes.Length + hostUrlLength +
                timeStampLengthBytes.Length + timeStampLength);

            expectedProof.AddRange(accessTokenLengthBytes);
            expectedProof.AddRange(accessTokenBytes);
            expectedProof.AddRange(hostUrlLengthBytes);
            expectedProof.AddRange(hostUrlBytes);
            expectedProof.AddRange(timeStampLengthBytes);
            expectedProof.AddRange(timeStampBytes);

            // create another byte[] from that list
            byte[] preSigningBytes = expectedProof.ToArray();

            return(new ProofKeyOutput(
                       accessToken,
                       accessTokenBytes,
                       accessTokenLength,
                       accessTokenLengthBytes,
                       hostUrl,
                       hostUrlBytes,
                       hostUrlLength,
                       hostUrlLengthBytes,
                       timeStamp,
                       timeStampBytes,
                       timeStampLength,
                       timeStampLengthBytes,
                       preSigningBytes));
        }
Пример #2
0
        public static ProofKeyOutput GetSignedProofData(ProofKeyInput proofData, RSACryptoServiceProvider rsaAlg)
        {
            ProofKeyOutput output = GetProofData(proofData);

            using (SHA256CryptoServiceProvider hashAlg = new SHA256CryptoServiceProvider())
            {
                byte[] signedProofBytes = rsaAlg.SignData(output.PreSigningBytes, hashAlg);
                output.SignedBase64ProofKey = Convert.ToBase64String(signedProofBytes);

                return(output);
            }
        }