List of usage examples for org.bouncycastle.asn1.x509 RSAPublicKeyStructure RSAPublicKeyStructure
public RSAPublicKeyStructure(ASN1Sequence seq)
From source file:cf.monteux.silvertunnel.netlib.layer.tor.util.Encryption.java
License:Open Source License
/** * makes RSA public key from bin byte array. * * @param b byte array that contains the key * @return/*from w ww .j av a2 s . co m*/ * @see JCERSAPublicKey */ public static RSAPublicKey extractBinaryRSAKey(final byte[] b) { RSAPublicKey theKey; try { final ASN1InputStream ais = new ASN1InputStream(b); final Object asnObject = ais.readObject(); final ASN1Sequence sequence = (ASN1Sequence) asnObject; final RSAPublicKeyStructure tempKey = new RSAPublicKeyStructure(sequence); theKey = getRSAPublicKey(tempKey.getModulus(), tempKey.getPublicExponent()); ais.close(); } catch (final IOException e) { logger.warn("Caught exception:" + e.getMessage()); theKey = null; } return theKey; }
From source file:com.rovemonteux.silvertunnel.netlib.layer.tor.util.Encryption.java
License:Open Source License
/** * makes RSA public key from bin byte array. * * @param b byte array that contains the key * @return//w w w. j av a 2s . co m * @see JCERSAPublicKey */ public static RSAPublicKey extractBinaryRSAKey(final byte[] b) { RSAPublicKey theKey; try { final ASN1InputStream ais = new ASN1InputStream(b); final Object asnObject = ais.readObject(); final ASN1Sequence sequence = (ASN1Sequence) asnObject; final RSAPublicKeyStructure tempKey = new RSAPublicKeyStructure(sequence); theKey = getRSAPublicKey(tempKey.getModulus(), tempKey.getPublicExponent()); ais.close(); } catch (final IOException e) { LOG.warn("Caught exception:" + e.getMessage()); theKey = null; } return theKey; }
From source file:org.jclouds.crypto.pem.PKCS1EncodedPublicKeySpec.java
License:Apache License
/** * Decode PKCS#1 encoded public key into RSAPublicKeySpec. * <p>// w w w. j a v a2s . com * Keys here can be in two different formats. They can have the algorithm * encoded, or they can have only the modulus and the public exponent. * <p> * The latter is not a valid PEM encoded file, but it is a valid DER encoded * RSA key, so this method should also support it. * * @param keyBytes * Encoded PKCS#1 rsa key. */ private void decode(final byte[] keyBytes) throws IOException { RSAPublicKeyStructure pks = null; ASN1Sequence seq = (ASN1Sequence) ASN1Object.fromByteArray(keyBytes); try { // Try to parse the public key normally. If the algorithm is not // present in the encoded key, an IllegalArgumentException will be // raised. SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(seq); pks = new RSAPublicKeyStructure((ASN1Sequence) info.getPublicKey()); } catch (IllegalArgumentException ex) { // If the algorithm is not found in the encoded key, try to extract // just the modulus and the public exponent to build the public key. pks = new RSAPublicKeyStructure(seq); } keySpec = new RSAPublicKeySpec(pks.getModulus(), pks.getPublicExponent()); }
From source file:org.jruby.ext.openssl.x509store.BouncyCastleASN1FormatHandler.java
License:LGPL
private RSAPublicKey readRSAPublicKey(BufferedReader in, String endMarker) throws IOException { ByteArrayInputStream bAIS = new ByteArrayInputStream(readBytes(in, endMarker)); ASN1InputStream ais = new ASN1InputStream(bAIS); Object asnObject = ais.readObject(); ASN1Sequence sequence = (ASN1Sequence) asnObject; RSAPublicKeyStructure rsaPubStructure = new RSAPublicKeyStructure(sequence); RSAPublicKeySpec keySpec = new RSAPublicKeySpec(rsaPubStructure.getModulus(), rsaPubStructure.getPublicExponent()); try {//from ww w . j ava2s . c o m KeyFactory keyFact = KeyFactory.getInstance("RSA"); return (RSAPublicKey) keyFact.generatePublic(keySpec); } catch (NoSuchAlgorithmException e) { // ignore } catch (InvalidKeySpecException e) { // ignore } return null; }
From source file:org.opensc.pkcs15.asn1.attr.RSAPublicKeyChoice.java
License:Apache License
public RSAPublicKeyChoice(SubjectPublicKeyInfo spki) { this.spki = spki; try {//from w ww . j a v a2 s.co m RSAPublicKeyStructure pubKey = new RSAPublicKeyStructure((ASN1Sequence) spki.getPublicKey()); this.raw = new RSAPublicKeyStructure(pubKey.getModulus(), pubKey.getPublicExponent()); } catch (IOException e) { throw new IllegalArgumentException("invalid info structure in RSA public key"); } }
From source file:org.silvertunnel.netlib.layer.tor.util.Encryption.java
License:Open Source License
/** * makes RSA public key from bin byte array * //w ww . ja va 2 s . com * @param s * string that contais the key * @return * @see JCERSAPublicKey */ public static RSAPublicKey extractBinaryRSAKey(byte[] b) { RSAPublicKey theKey; try { ASN1InputStream ais = new ASN1InputStream(b); Object asnObject = ais.readObject(); ASN1Sequence sequence = (ASN1Sequence) asnObject; RSAPublicKeyStructure tempKey = new RSAPublicKeyStructure(sequence); theKey = getRSAPublicKey(tempKey.getModulus(), tempKey.getPublicExponent()); } catch (IOException e) { log.warning("Caught exception:" + e.getMessage()); theKey = null; } return theKey; }
From source file:TorJava.Common.Encryption.java
License:Open Source License
/** * makes RSA public key from bin byte array * //www .j ava2 s. c o m * @param s * string that contais the key * @return * @see JCERSAPublicKey */ public static RSAPublicKeyStructure extractBinaryRSAKey(byte[] b) { RSAPublicKeyStructure theKey; try { ASN1InputStream ais = new ASN1InputStream(b); Object asnObject = ais.readObject(); ASN1Sequence sequence = (ASN1Sequence) asnObject; theKey = new RSAPublicKeyStructure(sequence); } catch (IOException e) { Logger.logDirectory(Logger.WARNING, "Caught exception:" + e.getMessage()); theKey = null; } return theKey; }