@Override public byte[] getEncoded() throws IOException { return super.getEncoded(); }
private void writeObject( ObjectOutputStream out) throws IOException { out.defaultWriteObject(); if (!algorithmIdentifier.equals(DEFAULT_ALGORITHM_IDENTIFIER)) { out.writeObject(algorithmIdentifier.getEncoded()); } } }
@Override public byte[] getEncodedAlgorithmIdentifier() { if (encodedAlgorithmIdentifier != null) { return encodedAlgorithmIdentifier; } try { return signer.getAlgorithmIdentifier().getEncoded(); } catch (IOException ex) { throw new IllegalStateException("error encoding AlgorithmIdentifier", ex); } }
@Override public byte[] getEncodedAlgorithmIdentifier() { if (encodedAlgorithmIdentifier != null) { return encodedAlgorithmIdentifier; } try { return signer.getAlgorithmIdentifier().getEncoded(); } catch (IOException ex) { throw new RuntimeException("error encoding AlgorithmIdentifier", ex); } }
@Override public byte[] getEncoded() throws IOException { return getAlgorithmIdentifier().getEncoded(); } }
@Override public byte[] getEncoded() throws IOException { return getAlgorithmIdentifier().getEncoded(); } }
public static byte[] getEncoded(final AlgorithmIdentifier algorithmIdentifier) throws DSSException { try { return algorithmIdentifier.getEncoded(ASN1Encoding.DER); } catch (IOException e) { throw new DSSException(e); } }
public XiWrappedContentSigner(ContentSigner signer, boolean fixedAlgorithmIdentifier) throws XiSecurityException { this.signer = Args.notNull(signer, "signer"); if (fixedAlgorithmIdentifier) { try { this.encodedAlgorithmIdentifier = signer.getAlgorithmIdentifier().getEncoded(); } catch (IOException ex) { throw new XiSecurityException("could not encode AlgorithmIdentifier", ex); } } }
public XiWrappedContentSigner(ContentSigner signer, boolean fixedAlgorithmIdentifier) throws XiSecurityException { this.signer = ParamUtil.requireNonNull("signer",signer); if (fixedAlgorithmIdentifier) { try { this.encodedAlgorithmIdentifier = signer.getAlgorithmIdentifier().getEncoded(); } catch (IOException ex) { throw new XiSecurityException("could not encode AlgorithmIdentifier", ex); } } }
public SignatureSigner(final AlgorithmIdentifier sigAlgId, final Signature signer, final PrivateKey key) throws XiSecurityException { this.sigAlgId = ParamUtil.requireNonNull("sigAlgId", sigAlgId); this.signer = ParamUtil.requireNonNull("signer", signer); this.key = ParamUtil.requireNonNull("key", key); try { this.encodedSigAlgId = sigAlgId.getEncoded(); } catch (IOException ex) { throw new XiSecurityException("could not encode AlgorithmIdentifier", ex); } }
P11ContentSigner(P11CryptService cryptService, P11IdentityId identityId, AlgorithmIdentifier signatureAlgId) throws XiSecurityException, P11TokenException { this.identityId = Args.notNull(identityId, "identityId"); this.cryptService = Args.notNull(cryptService, "cryptService"); this.algorithmIdentifier = Args.notNull(signatureAlgId, "signatureAlgId"); try { this.encodedAlgorithmIdentifier = algorithmIdentifier.getEncoded(); } catch (IOException ex) { throw new XiSecurityException("could not encode AlgorithmIdentifier", ex); } }
public SignatureSigner(AlgorithmIdentifier sigAlgId, Signature signer, PrivateKey key) throws XiSecurityException { this.sigAlgId = Args.notNull(sigAlgId, "sigAlgId"); this.signer = Args.notNull(signer, "signer"); this.key = Args.notNull(key, "key"); try { this.encodedSigAlgId = sigAlgId.getEncoded(); } catch (IOException ex) { throw new XiSecurityException("could not encode AlgorithmIdentifier", ex); } }
this.algorithmIdentifier = ParamUtil.requireNonNull("signatureAlgId", signatureAlgId); try { this.encodedAlgorithmIdentifier = algorithmIdentifier.getEncoded(); } catch (IOException ex) { throw new XiSecurityException("could not encode AlgorithmIdentifier", ex);
P11ECDSAContentSigner(final P11CryptService cryptService, final P11EntityIdentifier identityId, final AlgorithmIdentifier signatureAlgId, final boolean plain) throws XiSecurityException, P11TokenException { this.cryptService = ParamUtil.requireNonNull("cryptService", cryptService); this.identityId = ParamUtil.requireNonNull("identityId", identityId); this.algorithmIdentifier = ParamUtil.requireNonNull("signatureAlgId", signatureAlgId); try { this.encodedAlgorithmIdentifier = algorithmIdentifier.getEncoded(); } catch (IOException ex) { throw new XiSecurityException("could not encode AlgorithmIdentifier", ex); } this.plain = plain; String algOid = signatureAlgId.getAlgorithm().getId(); HashAlgoType hashAlgo = sigAlgHashMap.get(algOid); if (hashAlgo == null) { throw new XiSecurityException("unsupported signature algorithm " + algOid); } P11Slot slot = cryptService.getSlot(identityId.slotId()); if (slot.supportsMechanism(PKCS11Constants.CKM_ECDSA)) { this.mechanism = PKCS11Constants.CKM_ECDSA; Digest digest = SignerUtil.getDigest(hashAlgo); this.outputStream = new DigestOutputStream(digest); } else { this.mechanism = hashMechMap.get(hashAlgo).longValue(); if (!slot.supportsMechanism(this.mechanism)) { throw new XiSecurityException("unsupported signature algorithm " + algOid); } this.outputStream = new ByteArrayOutputStream(); } }
P11ECDSAContentSigner(P11CryptService cryptService, P11IdentityId identityId, AlgorithmIdentifier signatureAlgId, boolean plain) throws XiSecurityException, P11TokenException { this.cryptService = ParamUtil.requireNonNull("cryptService", cryptService); this.identityId = ParamUtil.requireNonNull("identityId", identityId); this.algorithmIdentifier = ParamUtil.requireNonNull("signatureAlgId", signatureAlgId); try { this.encodedAlgorithmIdentifier = algorithmIdentifier.getEncoded(); } catch (IOException ex) { throw new XiSecurityException("could not encode AlgorithmIdentifier", ex); } this.plain = plain; String algOid = signatureAlgId.getAlgorithm().getId(); HashAlgo hashAlgo = sigAlgHashMap.get(algOid); if (hashAlgo == null) { throw new XiSecurityException("unsupported signature algorithm " + algOid); } P11Slot slot = cryptService.getSlot(identityId.getSlotId()); if (slot.supportsMechanism(PKCS11Constants.CKM_ECDSA)) { this.mechanism = PKCS11Constants.CKM_ECDSA; Digest digest = hashAlgo.createDigest(); this.outputStream = new DigestOutputStream(digest); } else { this.mechanism = hashMechMap.get(hashAlgo).longValue(); if (!slot.supportsMechanism(this.mechanism)) { throw new XiSecurityException("unsupported signature algorithm " + algOid); } this.outputStream = new ByteArrayOutputStream(); } }
public HmacContentSigner(HashAlgo hashAlgo, AlgorithmIdentifier algorithmIdentifier, SecretKey signingKey) throws XiSecurityException { this.algorithmIdentifier = Args.notNull(algorithmIdentifier, "algorithmIdentifier"); Args.notNull(signingKey, "signingKey"); try { this.encodedAlgorithmIdentifier = algorithmIdentifier.getEncoded(); } catch (IOException ex) { throw new XiSecurityException("could not encode AlgorithmIdentifier", ex); } if (hashAlgo == null) { hashAlgo = AlgorithmUtil.extractHashAlgoFromMacAlg(algorithmIdentifier); } this.hmac = new HMac(hashAlgo.createDigest()); byte[] keyBytes = signingKey.getEncoded(); this.hmac.init(new KeyParameter(keyBytes, 0, keyBytes.length)); this.outLen = hmac.getMacSize(); this.outputStream = new HmacOutputStream(); }
public HmacContentSigner(HashAlgoType hashAlgo, AlgorithmIdentifier algorithmIdentifier, SecretKey signingKey) throws XiSecurityException { this.algorithmIdentifier = ParamUtil.requireNonNull("algorithmIdentifier", algorithmIdentifier); try { this.encodedAlgorithmIdentifier = algorithmIdentifier.getEncoded(); } catch (IOException ex) { throw new XiSecurityException("could not encode AlgorithmIdentifier", ex); } ParamUtil.requireNonNull("signingKey", signingKey); if (hashAlgo == null) { hashAlgo = AlgorithmUtil.extractHashAlgoFromMacAlg(algorithmIdentifier); } this.hmac = new HMac(hashAlgo.createDigest()); byte[] keyBytes = signingKey.getEncoded(); this.hmac.init(new KeyParameter(keyBytes, 0, keyBytes.length)); this.outLen = hmac.getMacSize(); this.outputStream = new HmacOutputStream(); }
this.algorithmIdentifier = ParamUtil.requireNonNull("signatureAlgId", signatureAlgId); try { this.encodedAlgorithmIdentifier = algorithmIdentifier.getEncoded(); } catch (IOException ex) { throw new XiSecurityException("could not encode AlgorithmIdentifier", ex);
this.algorithmIdentifier = ParamUtil.requireNonNull("macAlgId", macAlgId); try { this.encodedAlgorithmIdentifier = algorithmIdentifier.getEncoded(); } catch (IOException ex) { throw new XiSecurityException("could not encode AlgorithmIdentifier", ex);
@Override public boolean isSignedBy(PublicKeyParameters publicKey) throws GeneralSecurityException { TBSCertificate tbsCert = this.holder.toASN1Structure().getTBSCertificate(); if (!BcUtils.isAlgorithlIdentifierEqual(tbsCert.getSignature(), this.holder.getSignatureAlgorithm())) { return false; } Signer signer = null; // Optimisation if (this.signerFactory instanceof BcSignerFactory) { signer = ((BcSignerFactory) this.signerFactory).getInstance(false, publicKey, tbsCert.getSignature()); } else { try { signer = this.signerFactory.getInstance(false, publicKey, this.holder.getSignatureAlgorithm().getEncoded()); } catch (IOException e) { return false; } } try { return BcUtils.updateDEREncodedObject(signer, tbsCert).verify(this.holder.getSignature()); } catch (IOException e) { return false; } }