'How can I read JKS file in C#
I have been requested from my partner to use his API, and to use this API, I should encrypt all sent data to AES 256. He shared a .jks file with me, in addition to some parameters with values like (Alias, KEYSTORE_PASSWORD and KEY_PASSWORD), then he told me that the password which I should use for encryption is stored in that JKS file, and to open it, I should use the pre-shared parameters.
So, how can I reach that?
UPDATE ... This is not a web service am trying to invoke, I just need to get the Password which is stored in the JKS file, so, I am not going to invoke an API or import a certificate into my client app. So, it doesn't matter if opening the app by C# or any other tool, i just need to get the password in order to use it later in encrypting some data.
Solution 1:[1]
But you cannot access "TrustedCertEntry". It is a restriction. See: https://docs.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#InstallProbs
Solution 2:[2]
You can use fetch or libraries like axios.
Check this question how to do a POST request with fetch: Fetch: POST JSON data
Example POST request function with axios:
const sendToServer = async (products) => {
try {
// store response in variable if needed
const res = await axios.post(
"/your_api/products",
products // products you want to post
);
// return data in case
return res.data
} catch (error) {
console.log(error);
}
}
// implement this function where you need it
sendToServer(products)
or check POST examples in the axios documentation:
https://axios-http.com/docs/post_example
// Send a POST request
axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
// Send a POST request
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
}
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rainer Knöterich |
| Solution 2 | privateblocks |
