git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/common-encryption@124042 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
18a1c04d8f
commit
c612694ed6
|
@ -1,7 +1,7 @@
|
||||||
package org.gcube.common.encryption.keytool;
|
package org.gcube.common.encryption.keytool;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.security.Key;
|
import java.security.Key;
|
||||||
import java.security.KeyStore;
|
import java.security.KeyStore;
|
||||||
import java.security.KeyStoreException;
|
import java.security.KeyStoreException;
|
||||||
|
@ -12,6 +12,7 @@ import java.security.UnrecoverableKeyException;
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.security.interfaces.RSAPublicKey;
|
import java.security.interfaces.RSAPublicKey;
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,23 +74,6 @@ public class KeyTool {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Get public key from keystore.
|
|
||||||
* The public key is in the certificate.
|
|
||||||
*/
|
|
||||||
private static Key getPublicKey(String keyname, String keystore)
|
|
||||||
throws IOException, KeyStoreException, NoSuchAlgorithmException,
|
|
||||||
CertificateException {
|
|
||||||
|
|
||||||
KeyStore ks = KeyStore.getInstance("JKS");
|
|
||||||
ks.load(new FileInputStream(keystore), KEYSTORE_PASS.toCharArray());
|
|
||||||
X509Certificate cert = (X509Certificate) ks.getCertificate(keyname);
|
|
||||||
|
|
||||||
if (cert != null) {
|
|
||||||
return cert.getPublicKey();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Encrypt a message using the public key
|
* Encrypt a message using the public key
|
||||||
|
|
Loading…
Reference in New Issue