public static RSAPublicKey getInstance( Object obj) { if (obj instanceof RSAPublicKey) { return (RSAPublicKey)obj; } if (obj != null) { return new RSAPublicKey(ASN1Sequence.getInstance(obj)); } return null; }
BCRSAPublicKey( SubjectPublicKeyInfo info) { try { org.spongycastle.asn1.pkcs.RSAPublicKey pubKey = org.spongycastle.asn1.pkcs.RSAPublicKey.getInstance(info.parsePublicKey()); this.modulus = pubKey.getModulus(); this.publicExponent = pubKey.getPublicExponent(); } catch (IOException e) { throw new IllegalArgumentException("invalid info structure in RSA public key"); } }
private AsymmetricBlockCipher getAsymmetricCipher( SecurityAlgorithm algorithm, RSAPublicKey publicKey) throws ServiceResultException { CipherParameters params = new RSAKeyParameters(false, publicKey.getModulus(), publicKey.getPublicExponent()); // logger.info("Cipher: \nmodulus={}, \npublicExponent={}\n", // publicKey.getModulus(), publicKey.getPublicExponent()); return getAsymmetricCipher(true, algorithm, params); }
public static RSAPublicKey getInstance( ASN1TaggedObject obj, boolean explicit) { return getInstance(ASN1Sequence.getInstance(obj, explicit)); }
private Signer getAsymmetricSigner(boolean forSigning, SecurityAlgorithm algorithm, RSAPublicKey publicKey) throws ServiceResultException { CipherParameters params = new RSAKeyParameters(false, publicKey.getModulus(), publicKey.getPublicExponent()); return getAsymmetricSigner(forSigning, algorithm, params); }
public static RSAPublicKey getInstance( ASN1TaggedObject obj, boolean explicit) { return getInstance(ASN1Sequence.getInstance(obj, explicit)); }
JCERSAPublicKey( SubjectPublicKeyInfo info) { try { org.spongycastle.asn1.pkcs.RSAPublicKey pubKey = org.spongycastle.asn1.pkcs.RSAPublicKey.getInstance(info.parsePublicKey()); this.modulus = pubKey.getModulus(); this.publicExponent = pubKey.getPublicExponent(); } catch (IOException e) { throw new IllegalArgumentException("invalid info structure in RSA public key"); } }
public static RSAPublicKey getInstance( Object obj) { if (obj instanceof RSAPublicKey) { return (RSAPublicKey)obj; } if (obj != null) { return new RSAPublicKey(ASN1Sequence.getInstance(obj)); } return null; }
/** * This outputs the key in PKCS1v2 format. * <pre> * RSAPublicKey ::= SEQUENCE { * modulus INTEGER, -- n * publicExponent INTEGER, -- e * } * </pre> * <p> */ public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(new ASN1Integer(getModulus())); v.add(new ASN1Integer(getPublicExponent())); return new DERSequence(v); } }
public Object parseObject(PemObject obj) throws IOException { try { RSAPublicKey rsaPubStructure = RSAPublicKey.getInstance(obj.getContent()); return new SubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), rsaPubStructure); } catch (IOException e) { throw e; } catch (Exception e) { throw new PEMException("problem extracting key: " + e.toString(), e); } } }
private void populateFromPublicKeyInfo(SubjectPublicKeyInfo info) { try { org.spongycastle.asn1.pkcs.RSAPublicKey pubKey = org.spongycastle.asn1.pkcs.RSAPublicKey.getInstance(info.parsePublicKey()); this.algorithmIdentifier = info.getAlgorithm(); this.modulus = pubKey.getModulus(); this.publicExponent = pubKey.getPublicExponent(); } catch (IOException e) { throw new IllegalArgumentException("invalid info structure in RSA public key"); } }
/** {@inheritDoc} */ @Override public boolean verifyAsymm(PublicKey signingCertificate, SecurityAlgorithm algorithm, byte[] dataToVerify, byte[] signature) throws ServiceResultException { if (algorithm == null) return true; if (signingCertificate == null || dataToVerify == null || signature == null) throw new IllegalArgumentException("null arg"); java.security.interfaces.RSAPublicKey signingCertificateRSA = (java.security.interfaces.RSAPublicKey) signingCertificate; RSAPublicKey publicKey = new RSAPublicKey( signingCertificateRSA.getModulus(), signingCertificateRSA.getPublicExponent()); Signer signer = getAsymmetricSigner(false, algorithm, publicKey); signer.update(dataToVerify, 0, dataToVerify.length); return signer.verifySignature(signature); }
/** * This outputs the key in PKCS1v2 format. * <pre> * RSAPublicKey ::= SEQUENCE { * modulus INTEGER, -- n * publicExponent INTEGER, -- e * } * </pre> * <p> */ public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(new ASN1Integer(getModulus())); v.add(new ASN1Integer(getPublicExponent())); return new DERSequence(v); } }
public Object parseObject(PemObject obj) throws IOException { try { RSAPublicKey rsaPubStructure = RSAPublicKey.getInstance(obj.getContent()); return new SubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), rsaPubStructure); } catch (IOException e) { throw e; } catch (Exception e) { throw new PEMException("problem extracting key: " + e.toString(), e); } } }
|| algId.getAlgorithm().equals(X509ObjectIdentifiers.id_ea_rsa)) RSAPublicKey pubKey = RSAPublicKey.getInstance(keyInfo.parsePublicKey()); return new RSAKeyParameters(false, pubKey.getModulus(), pubKey.getPublicExponent());
public byte[] getEncoded() { return KeyUtil.getEncodedSubjectPublicKeyInfo(algorithmIdentifier, new org.spongycastle.asn1.pkcs.RSAPublicKey(getModulus(), getPublicExponent())); }
|| algId.getAlgorithm().equals(X509ObjectIdentifiers.id_ea_rsa)) RSAPublicKey pubKey = RSAPublicKey.getInstance(keyInfo.parsePublicKey()); return new RSAKeyParameters(false, pubKey.getModulus(), pubKey.getPublicExponent());
/** {@inheritDoc} */ public void encryptAsymm(PublicKey encryptingCertificate, SecurityAlgorithm algorithm, byte[] dataToEncrypt, byte[] output, int outputOffset) throws ServiceResultException { try { java.security.interfaces.RSAPublicKey encryptingCertificateRSA = (java.security.interfaces.RSAPublicKey) encryptingCertificate; RSAPublicKey publicKey = new RSAPublicKey( encryptingCertificateRSA.getModulus(), encryptingCertificateRSA.getPublicExponent()); AsymmetricBlockCipher cipher = getAsymmetricCipher(algorithm, publicKey); int len = 0; int inputBlockSize = cipher.getInputBlockSize(); int outputBlockSize = cipher.getOutputBlockSize(); logger.debug( "Encrypt: inputBlockSize={}, outputBlockSize={}, dataToEncrypt.length={}", inputBlockSize, outputBlockSize, dataToEncrypt.length); for (int i = 0; i < dataToEncrypt.length; i += inputBlockSize) { int size = Math.min(dataToEncrypt.length - i, inputBlockSize); byte[] tmp = cipher.processBlock(dataToEncrypt, i, size); System.arraycopy(tmp, 0, output, outputOffset + len, tmp.length); len += tmp.length; } } catch (InvalidCipherTextException e) { throw new ServiceResultException(StatusCodes.Bad_InternalError, e); } }
public byte[] getEncoded() { return KeyUtil.getEncodedSubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new org.spongycastle.asn1.pkcs.RSAPublicKey(getModulus(), getPublicExponent())); }
public byte[] getEncoded() { return KeyUtil.getEncodedSubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, new DERNull()), new org.spongycastle.asn1.pkcs.RSAPublicKey(getModulus(), getPublicExponent())); }