Last active
February 3, 2017 06:35
-
-
Save babafeng/bb53ca7594c7e54ccbe5d6ebf995c199 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| try { | |
| AssetManager asset = getResources().getAssets(); | |
| CertificateFactory certificateFactory = CertificateFactory.getInstance("X509"); | |
| InputStream cerInputStream = asset.open("demons.cer"); | |
| Certificate certificate = certificateFactory.generateCertificate(cerInputStream); | |
| RSAPublicKey publicKey = (RSAPublicKey) certificate.getPublicKey(); | |
| Log.d(TAG, " public: " + publicKey); | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } catch (CertificateException e) { | |
| e.printStackTrace(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| try { | |
| InputStream cerInputStream = new FileInputStream("C:\\holmes\\Java\\demons.cer"); | |
| CertificateFactory certificateFactory = CertificateFactory.getInstance("X509"); | |
| Certificate certificate = certificateFactory.generateCertificate(cerInputStream); | |
| RSAPublicKey publicKeyx = (RSAPublicKey) certificate.getPublicKey(); | |
| System.out.println(publicKeyx); | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } catch (CertificateException e) { | |
| e.printStackTrace(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class java_keystore { | |
| public static void main(String args[]) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException { | |
| // keystore pass | |
| String store_pass = "demons"; | |
| InputStream inputStream = new FileInputStream("C:\\holmes\\Java\\demons.keystore"); | |
| KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); | |
| keyStore.load(inputStream, store_pass.toCharArray()); | |
| // alias | |
| String alias = "demons"; | |
| // key pass | |
| String key_pass = "demons"; | |
| // privateKey | |
| PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, key_pass.toCharArray()); | |
| // publicKey | |
| PublicKey publicKey = keyStore.getCertificate(alias).getPublicKey(); | |
| System.out.println(privateKey); | |
| System.out.println(publicKey); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment