Uses 15838K of libraries. Click here for Pure Java version (2215L/12K).
1 | !7 |
2 | |
3 | !include once #1030462 // BouncyCastle |
4 | |
5 | cprint { |
6 | KeyPair generateKeyPair() ctex { |
7 | ECNamedCurveParameterSpec parameterSpec = ECNamedCurveTable.getParameterSpec(nl.martijndwars.webpush.Utils.CURVE); |
8 | |
9 | KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(nl.martijndwars.webpush.Utils.ALGORITHM, |
10 | org.bouncycastle.jce.provider.BouncyCastleProvider.PROVIDER_NAME); |
11 | keyPairGenerator.initialize(parameterSpec); |
12 | |
13 | ret keyPairGenerator.generateKeyPair(); |
14 | } |
15 | |
16 | start-thread { |
17 | Provider provider = Security.getProvider(org.bouncycastle.jce.provider.BouncyCastleProvider.PROVIDER_NAME); |
18 | print("Provider:" + provider); |
19 | if (provider == null) { |
20 | Security.addProvider(new BouncyCastleProvider); |
21 | provider = Security.getProvider(org.bouncycastle.jce.provider.BouncyCastleProvider.PROVIDER_NAME); |
22 | print("Provider:" + provider); |
23 | } |
24 | |
25 | KeyPair keyPair = generateKeyPair(); |
26 | ECPublicKey publicKey = cast keyPair.getPublic(); |
27 | ECPrivateKey privateKey = cast keyPair.getPrivate(); |
28 | |
29 | byte[] encodedPublicKey = nl.martijndwars.webpush.Utils.encode(publicKey); |
30 | byte[] encodedPrivateKey = nl.martijndwars.webpush.Utils.encode(privateKey); |
31 | |
32 | print("Public key: " + base64encode(encodedPublicKey)); |
33 | print("Private key: " + shorten(16, base64encode(encodedPrivateKey))); |
34 | } |
35 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1030460 |
Snippet name: | Test web-push-libs [generate key] |
Eternal ID of this version: | #1030460/11 |
Text MD5: | e537fcf106405002ab0ea6a5cf8f1c8a |
Transpilation MD5: | 64c7eb6c8308eda7e6a2a4dc44accfdf |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-12-21 17:16:17 |
Source code size: | 1382 bytes / 35 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 185 / 331 |
Version history: | 10 change(s) |
Referenced in: | [show references] |