Skip to content

Commit a0ae9de

Browse files
author
Cory Thompson
committed
Pad generated vapid private key if required.
1 parent cbc6f82 commit a0ae9de

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

WebPush/VapidHelper.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public static class VapidHelper
1010
/// <summary>
1111
/// Generate vapid keys
1212
/// </summary>
13-
/// <returns></returns>
1413
public static VapidDetails GenerateVapidKeys()
1514
{
1615
var results = new VapidDetails();
@@ -20,7 +19,7 @@ public static VapidDetails GenerateVapidKeys()
2019
var privateKey = ((ECPrivateKeyParameters) keys.Private).D.ToByteArrayUnsigned();
2120

2221
results.PublicKey = UrlBase64.Encode(publicKey);
23-
results.PrivateKey = UrlBase64.Encode(privateKey);
22+
results.PrivateKey = UrlBase64.Encode(ByteArrayPadLeft(privateKey, 32));
2423

2524
return results;
2625
}
@@ -146,5 +145,13 @@ private static long UnixTimeNow()
146145
var timeSpan = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0);
147146
return (long) timeSpan.TotalSeconds;
148147
}
148+
149+
private static byte[] ByteArrayPadLeft(byte[] src, int size)
150+
{
151+
var dst = new byte[size];
152+
var startAt = dst.Length - src.Length;
153+
Array.Copy(src, 0, dst, startAt, src.Length);
154+
return dst;
155+
}
149156
}
150157
}

WebPush/WebPushClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ public async Task SendNotificationAsync(PushSubscription subscription, string pa
331331
}
332332

333333
/// <summary>
334-
/// Handle Web Push responses.
334+
/// Handle Web Push responses.
335335
/// </summary>
336336
/// <param name="response"></param>
337337
/// <param name="subscription"></param>

0 commit comments

Comments
 (0)