Comments (2)
Actually the Java code has a method to generate the PrivateKey
from the string, see below.
I think if we had something similar in javascript that would help.
We could probably create a PrivateKeyInput
from the string token but this needs some digging in the cryptography libraries.
Java:
public static PrivateKey importPrivateKey(String encodedPrivateKey) {
byte[] dBytes = Base64.getUrlDecoder().decode(encodedPrivateKey);
try {
BigInteger privateKeyInt = new BigInteger(1, dBytes);
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(EC_ALGORITHM);
AlgorithmParameterSpec prime256v1ParamSpec = new ECGenParameterSpec(EC_CURVE);
keyPairGenerator.initialize(prime256v1ParamSpec);
ECParameterSpec parameterSpec = ((ECKey) keyPairGenerator.generateKeyPair().getPrivate()).getParams();
ECPrivateKeySpec privateKeySpec = new ECPrivateKeySpec(privateKeyInt, parameterSpec);
return KeyFactory.getInstance(EC_ALGORITHM).generatePrivate(privateKeySpec);
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | InvalidKeySpecException ex) {
throw new IllegalArgumentException("Failed to decode " + encodedPrivateKey, ex);
}
}
from nodejs-questdb-client.
The difference is that the node.js client produces the private key from the JWK format provided as input.
The Java client, for example, just takes the private key directly.
Java:
public final void authenticate(String keyId, PrivateKey privateKey);
The node.js client uses this API to create the private key from JWK format:
Creates and returns a new key object containing a private key.
If key is a string or Buffer, format is assumed to be 'pem';
otherwise, key must be an object with the properties described above.
If the private key is encrypted, a passphrase must be specified.
The length of the passphrase is limited to 1024 bytes.
Since:
v11.6.0
function createPrivateKey(key: PrivateKeyInput | string | Buffer | JsonWebKeyInput): KeyObject;
from nodejs-questdb-client.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodejs-questdb-client.