/** * Creates an ExternalSignature instance * @param pk a PrivateKey object * @param hashAlgorithm the hash algorithm (e.g. "SHA-1", "SHA-256",...) * @param provider the security provider (e.g. "BC") */ public PrivateKeySignature(PrivateKey pk, String hashAlgorithm, String provider) { this.pk = pk; this.provider = provider; this.hashAlgorithm = DigestAlgorithms.getDigest(DigestAlgorithms.getAllowedDigests(hashAlgorithm)); encryptionAlgorithm = pk.getAlgorithm(); if (encryptionAlgorithm.startsWith("EC")) { encryptionAlgorithm = "ECDSA"; } }
/** * Creates an ExternalSignature instance * @param pk a PrivateKey object * @param hashAlgorithm the hash algorithm (e.g. "SHA-1", "SHA-256",...) * @param provider the security provider (e.g. "BC") */ public PrivateKeySignature(PrivateKey pk, String hashAlgorithm, String provider) { this.pk = pk; this.provider = provider; this.hashAlgorithm = DigestAlgorithms.getDigest(DigestAlgorithms.getAllowedDigests(hashAlgorithm)); encryptionAlgorithm = pk.getAlgorithm(); if (encryptionAlgorithm.startsWith("EC")) { encryptionAlgorithm = "ECDSA"; } }
this.interfaceDigest = interfaceDigest; digestAlgorithmOid = DigestAlgorithms.getAllowedDigests(hashAlgorithm); if (digestAlgorithmOid == null) throw new NoSuchAlgorithmException(MessageLocalization.getComposedMessage("unknown.hash.algorithm.1", hashAlgorithm));
this.interfaceDigest = interfaceDigest; digestAlgorithmOid = DigestAlgorithms.getAllowedDigests(hashAlgorithm); if (digestAlgorithmOid == null) throw new NoSuchAlgorithmException(MessageLocalization.getComposedMessage("unknown.hash.algorithm.1", hashAlgorithm));
public MessageDigest getMessageDigest(String hashAlgorithm) throws GeneralSecurityException { String oid = DigestAlgorithms.getAllowedDigests(hashAlgorithm); if (oid == null) throw new NoSuchAlgorithmException(hashAlgorithm);
public MessageDigest getMessageDigest(String hashAlgorithm) throws GeneralSecurityException { String oid = DigestAlgorithms.getAllowedDigests(hashAlgorithm); if (oid == null) throw new NoSuchAlgorithmException(hashAlgorithm);
SignaturePolicyIdentifier toSignaturePolicyIdentifier() { String algId = DigestAlgorithms.getAllowedDigests(this.policyDigestAlgorithm); if (algId == null || algId.length() == 0) { throw new IllegalArgumentException("Invalid policy hash algorithm"); } SignaturePolicyIdentifier signaturePolicyIdentifier = null; SigPolicyQualifierInfo spqi = null; if (this.policyUri != null && this.policyUri.length() > 0) { spqi = new SigPolicyQualifierInfo(PKCSObjectIdentifiers.id_spq_ets_uri, new DERIA5String(this.policyUri)); } SigPolicyQualifiers qualifiers = new SigPolicyQualifiers(new SigPolicyQualifierInfo[] {spqi}); signaturePolicyIdentifier = new SignaturePolicyIdentifier(new SignaturePolicyId(DERObjectIdentifier.getInstance(new DERObjectIdentifier(this.policyIdentifier.replace("urn:oid:", ""))), new OtherHashAlgAndValue(new AlgorithmIdentifier(algId), new DEROctetString(this.policyHash)), qualifiers)); return signaturePolicyIdentifier; } }
SignaturePolicyIdentifier toSignaturePolicyIdentifier() { String algId = DigestAlgorithms.getAllowedDigests(this.policyDigestAlgorithm); if (algId == null || algId.length() == 0) { throw new IllegalArgumentException("Invalid policy hash algorithm"); } SignaturePolicyIdentifier signaturePolicyIdentifier = null; SigPolicyQualifierInfo spqi = null; if (this.policyUri != null && this.policyUri.length() > 0) { spqi = new SigPolicyQualifierInfo(PKCSObjectIdentifiers.id_spq_ets_uri, new DERIA5String(this.policyUri)); } SigPolicyQualifiers qualifiers = new SigPolicyQualifiers(new SigPolicyQualifierInfo[] {spqi}); signaturePolicyIdentifier = new SignaturePolicyIdentifier(new SignaturePolicyId(DERObjectIdentifier.getInstance(new DERObjectIdentifier(this.policyIdentifier.replace("urn:oid:", ""))), new OtherHashAlgAndValue(new AlgorithmIdentifier(algId), new DEROctetString(this.policyHash)), qualifiers)); return signaturePolicyIdentifier; } }
TimeStampRequest request = tsqGenerator.generate(new ASN1ObjectIdentifier(DigestAlgorithms.getAllowedDigests(digestAlgorithm)), imprint, nonce); byte[] requestBytes = request.getEncoded();
TimeStampRequest request = tsqGenerator.generate(new ASN1ObjectIdentifier(DigestAlgorithms.getAllowedDigests(digestAlgorithm)), imprint, nonce); byte[] requestBytes = request.getEncoded();
String sha256Oid = DigestAlgorithms.getAllowedDigests(DigestAlgorithms.SHA256);
String sha256Oid = DigestAlgorithms.getAllowedDigests(DigestAlgorithms.SHA256);