public static byte[] getEncodedSubjectPublicKeyInfo(SubjectPublicKeyInfo info) { try { return info.getEncoded(ASN1Encoding.DER); } catch (Exception e) { return null; } }
public static byte[] getEncodedSubjectPublicKeyInfo(SubjectPublicKeyInfo info) { try { return info.getEncoded(ASN1Encoding.DER); } catch (Exception e) { return null; } }
RSAPublicKeyStructure rsaPublicKey = /* ... */ AlgorithmIdentifier rsaEncryption = new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, null); SubjectPublicKeyInfo publicKeyInfo = new SubjectPublicKeyInfo(rsaEncryption, rsaPublicKey); byte[] encodedPublicKeyInfo = publicKeyInfo.getEncoded();
public byte[] getEncoded() { try { SubjectPublicKeyInfo pki = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(keyParams); return pki.getEncoded(); } catch (IOException e) { return null; } }
public byte[] getEncoded() { try { SubjectPublicKeyInfo pki = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(keyParams); return pki.getEncoded(); } catch (IOException e) { return null; } }
@Override public byte[] getEncoded() { try { return getSubjectPublicKeyInfo().getEncoded(); } catch (IOException e) { return null; } } }
public byte[] getEncoded() { try { SubjectPublicKeyInfo pki = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(keyParams); return pki.getEncoded(); } catch (IOException e) { return null; } }
public byte[] getEncoded() { try { SubjectPublicKeyInfo pki = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(params); return pki.getEncoded(); } catch (IOException e) { return null; } }
@Override public byte[] getEncoded() { try { return SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(parameters).getEncoded(); } catch (IOException e) { return null; } } }
PEMParser pemParser = new PEMParser(new StringReader(publicKey)); SubjectPublicKeyInfo spki = (SubjectPublicKeyInfo) pemParser.readObject(); pemParser.close(); byte [] spkiEncoded = spki.getEncoded(); X509EncodedKeySpec keySpec = new X509EncodedKeySpec(spkiEncoded); KeyFactory kf = KeyFactory.getInstance("RSA"); this.publicKey = kf.generatePublic(keySpec);
private static KeyPair loadPrivateKey(final String certPath) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException { Path path = Paths.get(certPath, "key.pem"); BufferedReader reader = Files.newBufferedReader(path, Charset.defaultCharset()); PEMParser parser = new PEMParser(reader); Object object = parser.readObject(); PEMKeyPair keyPair = (PEMKeyPair) object; byte[] privateEncoded = keyPair.getPrivateKeyInfo().getEncoded(); byte[] publicEncoded = keyPair.getPublicKeyInfo().getEncoded(); KeyFactory factory = KeyFactory.getInstance("RSA"); X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(publicEncoded); PublicKey publicKey = factory.generatePublic(publicKeySpec); PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(privateEncoded); PrivateKey privateKey = factory.generatePrivate(privateKeySpec); return new KeyPair(publicKey, privateKey); }
public static PublicKey getRSAPublicKey(byte[] encodedPubKey) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException { RSAPublicKey pubKey8 = RSAPublicKey.getInstance(encodedPubKey); SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(new RSAKeyParameters(false, pubKey8.getModulus(), pubKey8.getPublicExponent())); X509EncodedKeySpec spec = new X509EncodedKeySpec(info.getEncoded()); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); return keyFactory.generatePublic(spec); }
public static PublicKey getRSAPublicKey(byte[] encodedPubKey) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException { RSAPublicKey pubKey8 = RSAPublicKey.getInstance(encodedPubKey); SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(new RSAKeyParameters(false, pubKey8.getModulus(), pubKey8.getPublicExponent())); X509EncodedKeySpec spec = new X509EncodedKeySpec(info.getEncoded()); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); return keyFactory.generatePublic(spec); }
public static TransactionId sha1TransactionId(SubjectPublicKeyInfo spki) throws InvalidKeySpecException { ScepUtil.requireNonNull("spki", spki); byte[] encoded; try { encoded = spki.getEncoded(); } catch (IOException ex) { throw new InvalidKeySpecException("IOException while "); } return sha1TransactionId(encoded); }
private static byte[] getEncoded(NHPublicKeyParameters pubKey) { SubjectPublicKeyInfo pki; try { AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(PQCObjectIdentifiers.newHope); pki = new SubjectPublicKeyInfo(algorithmIdentifier, pubKey.getPubData()); return pki.getEncoded(); } catch (IOException e) { return null; } }
@Override public PublicKey generatePublic(SubjectPublicKeyInfo publicKeyInfo) throws IOException { AsymmetricKeyFactory factory = getKeyFactory(publicKeyInfo); if (factory instanceof AsymmetricKeyInfoConverter) { return ((AsymmetricKeyInfoConverter) factory).generatePublic(publicKeyInfo); } return factory.toKey(fromX509(publicKeyInfo.getEncoded())); } }
@Override public PublicKey generatePublic(SubjectPublicKeyInfo publicKeyInfo) throws IOException { AsymmetricKeyFactory factory = getKeyFactory(publicKeyInfo); if (factory instanceof AsymmetricKeyInfoConverter) { return ((AsymmetricKeyInfoConverter) factory).generatePublic(publicKeyInfo); } return factory.toKey(fromX509(publicKeyInfo.getEncoded())); } }
/** * @return Encoded PrivateKeyInfo structure in the case of a private key, otherwise an encoded SubjectPublicKeyInfo * structure. */ @Override public byte[] getEncoded() { try { if (delegate.isPrivate()) { return PrivateKeyInfoFactory.createPrivateKeyInfo(delegate).getEncoded(); } return SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(delegate).getEncoded(); } catch (IOException e) { throw new EncodingException("Key encoding error", e); } } }
public byte[] getEncoded() { try { if (dsaSpec == null) { return new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa), new ASN1Integer(y)).getEncoded(ASN1Encoding.DER); } return new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa, new DSAParameter(dsaSpec.getP(), dsaSpec.getQ(), dsaSpec.getG())), new ASN1Integer(y)).getEncoded(ASN1Encoding.DER); } catch (IOException e) { return null; } }
public byte[] getEncoded() { try { SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(OIWObjectIdentifiers.elGamalAlgorithm, new ElGamalParameter(elSpec.getP(), elSpec.getG())), new ASN1Integer(y)); return info.getEncoded(ASN1Encoding.DER); } catch (IOException e) { return null; } }