public static RSAPublicKey getInstance( Object obj) { if (obj instanceof RSAPublicKey) { return (RSAPublicKey)obj; } if (obj != null) { return new RSAPublicKey(ASN1Sequence.getInstance(obj)); } return null; }
public static RSAPublicKey getInstance( Object obj) { if (obj instanceof RSAPublicKey) { return (RSAPublicKey)obj; } if (obj != null) { return new RSAPublicKey(ASN1Sequence.getInstance(obj)); } return null; }
/** {@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); }
public byte[] getEncoded() { return KeyUtil.getEncodedSubjectPublicKeyInfo(algorithmIdentifier, new org.spongycastle.asn1.pkcs.RSAPublicKey(getModulus(), 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())); }
/** * Render the public key in X.509 SPKI ASN.1 format. * * @throws TelehashException */ public byte[] getSPKIEncoded() throws TelehashException { RSAKeyParameters param = (RSAKeyParameters)mKey; org.spongycastle.asn1.pkcs.RSAPublicKey asn1Key = new org.spongycastle.asn1.pkcs.RSAPublicKey( param.getModulus(), param.getExponent() ); SubjectPublicKeyInfo info; try { info = new SubjectPublicKeyInfo( new AlgorithmIdentifier( PKCSObjectIdentifiers.rsaEncryption, null ), asn1Key ); } catch (IOException e) { throw new TelehashException(e); } try { return info.getEncoded("DER"); } catch (IOException e) { throw new TelehashException(e); } }
public PEMKeyPair parse(byte[] encoding) throws IOException { try { ASN1Sequence seq = ASN1Sequence.getInstance(encoding); if (seq.size() != 9) { throw new PEMException("malformed sequence in RSA private key"); } org.spongycastle.asn1.pkcs.RSAPrivateKey keyStruct = org.spongycastle.asn1.pkcs.RSAPrivateKey.getInstance(seq); RSAPublicKey pubSpec = new RSAPublicKey( keyStruct.getModulus(), keyStruct.getPublicExponent()); AlgorithmIdentifier algId = new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE); return new PEMKeyPair(new SubjectPublicKeyInfo(algId, pubSpec), new PrivateKeyInfo(algId, keyStruct)); } catch (IOException e) { throw e; } catch (Exception e) { throw new PEMException( "problem creating RSA private key: " + e.toString(), e); } } }
public PEMKeyPair parse(byte[] encoding) throws IOException { try { ASN1Sequence seq = ASN1Sequence.getInstance(encoding); if (seq.size() != 9) { throw new PEMException("malformed sequence in RSA private key"); } org.spongycastle.asn1.pkcs.RSAPrivateKey keyStruct = org.spongycastle.asn1.pkcs.RSAPrivateKey.getInstance(seq); RSAPublicKey pubSpec = new RSAPublicKey( keyStruct.getModulus(), keyStruct.getPublicExponent()); AlgorithmIdentifier algId = new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE); return new PEMKeyPair(new SubjectPublicKeyInfo(algId, pubSpec), new PrivateKeyInfo(algId, keyStruct)); } catch (IOException e) { throw e; } catch (Exception e) { throw new PEMException( "problem creating RSA private key: " + e.toString(), e); } } }
return new SubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPublicKey(pub.getModulus(), pub.getExponent()));