|
3 | 3 | using System.Globalization; |
4 | 4 | using System.Security.Cryptography; |
5 | 5 | using Org.BouncyCastle.Math; |
6 | | -using Org.BouncyCastle.Crypto.Parameters; |
7 | 6 | using Org.BouncyCastle.Crypto.Signers; |
8 | 7 | using Lib.Net.Http.WebPush.Internals; |
9 | 8 |
|
@@ -59,11 +58,12 @@ internal WebPushSchemeHeadersValues(string authenticationHeaderValueParameter, s |
59 | 58 | private string _subject; |
60 | 59 | private string _publicKey; |
61 | 60 | private string _privateKey; |
62 | | - private ECPrivateKeyParameters _privateSigningKey; |
63 | 61 | private int _relativeExpiration; |
64 | 62 |
|
65 | 63 | private static readonly DateTime _unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0); |
66 | 64 | private static readonly string _jwtHeaderSegment = UrlBase64Converter.ToUrlBase64String(Encoding.UTF8.GetBytes(JWT_HEADER)); |
| 65 | + |
| 66 | + private ECDsaSigner _jwtSigner; |
67 | 67 | #endregion |
68 | 68 |
|
69 | 69 | #region Properties |
@@ -140,7 +140,9 @@ public string PrivateKey |
140 | 140 | } |
141 | 141 |
|
142 | 142 | _privateKey = value; |
143 | | - _privateSigningKey = ECKeyHelper.GetECPrivateKeyParameters(decodedPrivateKey); |
| 143 | + |
| 144 | + _jwtSigner = new ECDsaSigner(); |
| 145 | + _jwtSigner.Init(true, ECKeyHelper.GetECPrivateKeyParameters(decodedPrivateKey)); |
144 | 146 | } |
145 | 147 | } |
146 | 148 |
|
@@ -240,10 +242,7 @@ private string GenerateToken(string audience, DateTime absoluteExpiration) |
240 | 242 | jwtInputHash = sha256Hasher.ComputeHash(Encoding.UTF8.GetBytes(jwtInput)); |
241 | 243 | } |
242 | 244 |
|
243 | | - ECDsaSigner jwtSigner = new ECDsaSigner(); |
244 | | - jwtSigner.Init(true, _privateSigningKey); |
245 | | - |
246 | | - BigInteger[] jwtSignature = jwtSigner.GenerateSignature(jwtInputHash); |
| 245 | + BigInteger[] jwtSignature = _jwtSigner.GenerateSignature(jwtInputHash); |
247 | 246 |
|
248 | 247 | byte[] jwtSignatureFirstSegment = jwtSignature[0].ToByteArrayUnsigned(); |
249 | 248 | byte[] jwtSignatureSecondSegment = jwtSignature[1].ToByteArrayUnsigned(); |
@@ -289,7 +288,7 @@ private static void ByteArrayCopyWithPadLeft(byte[] sourceArray, byte[] destinat |
289 | 288 | destinationIndex += (destinationLengthToUse - sourceArray.Length); |
290 | 289 | } |
291 | 290 |
|
292 | | - Array.Copy(sourceArray, 0, destinationArray, destinationIndex, sourceArray.Length); |
| 291 | + Buffer.BlockCopy(sourceArray, 0, destinationArray, destinationIndex, sourceArray.Length); |
293 | 292 | } |
294 | 293 | #endregion |
295 | 294 | } |
|
0 commit comments