public static HashAlgo detectOcspDbCerthashAlgo(DataSourceWrapper datasource) throws DataAccessException { String str = datasource.getFirstValue(null, "DBSCHEMA", "VALUE2", "NAME='CERTHASH_ALGO'", String.class); return HashAlgo.getNonNullInstance(str); }
private static void formatString(Integer index, boolean verbose, StringBuilder sb, X509Certificate cert) { String subject = X509Util.getRfc4519Name(cert.getSubjectX500Principal()); sb.append("\t\tCertificate"); if (index != null) { sb.append("[").append(index).append("]"); } sb.append(": "); if (!verbose) { sb.append(subject).append("\n"); return; } sb.append("\n\t\t\tSubject: ").append(subject); String issuer = X509Util.getRfc4519Name(cert.getIssuerX500Principal()); sb.append("\n\t\t\tIssuer: ").append(issuer); sb.append("\n\t\t\tSerial: ").append(LogUtil.formatCsn(cert.getSerialNumber())); sb.append("\n\t\t\tStart time: ").append(cert.getNotBefore()); sb.append("\n\t\t\tEnd time: ").append(cert.getNotAfter()); sb.append("\n\t\t\tSHA1 Sum: "); try { sb.append(HashAlgo.SHA1.hexHash(cert.getEncoded())); } catch (CertificateEncodingException ex) { sb.append("ERROR"); } sb.append("\n"); }
protected P11RSADigestSignatureSpi(HashAlgo digestAlg) { this.digestAlgId = digestAlg.getAlgorithmIdentifier(); this.digest = digestAlg.createDigest(); }
public static ASN1ObjectIdentifier getHashAlg(String hashAlgName) throws NoSuchAlgorithmException { Args.notBlank(hashAlgName, "hashAlgName"); HashAlgo hashAlgo = HashAlgo.getInstance(hashAlgName.toUpperCase()); if (hashAlgo == null) { throw new NoSuchAlgorithmException("Unsupported hash algorithm " + hashAlgName); } return hashAlgo.getOid(); } // method getHashAlg
public static int getHashOutputSizeInOctets(ASN1ObjectIdentifier hashAlgo) throws NoSuchAlgorithmException { Args.notNull(hashAlgo, "hashAlgo"); HashAlgo hashAlgoType = HashAlgo.getInstance(hashAlgo); if (hashAlgoType == null) { throw new NoSuchAlgorithmException("Unsupported hash algorithm " + hashAlgo.getId()); } return hashAlgoType.getLength(); } // method getHashOutputSizeInOctets
HashAlgo ha; try { ha = HashAlgo.getNonNullInstance(algo); } catch (Exception ex) { throw new InvalidConfException("invalid pbmPwf " + algo, ex); canonicalizedAlgos.add(ha.getName()); requestPbmOwfs.add(ha.getOid()); responsePbmOwf = ha.getAlgorithmIdentifier();
byte[] spkiSha1 = HashAlgo.SHA1.hash( cert.getSubjectPublicKeyInfo().getPublicKeyData().getBytes()); if (Arrays.equals(respIdByKey, spkiSha1)) { HashAlgo hashAlgo = HashAlgo.getNonNullInstance(certId.getHashAlgOID()); boolean issuerMatch = issuerHash.match(hashAlgo, certId.getIssuerNameHash(), certId.getIssuerKeyHash());
private OCSPRequest buildRequest(X509Certificate caCert, BigInteger[] serialNumbers, byte[] nonce, RequestOptions requestOptions) throws OcspRequestorException { HashAlgo hashAlgo = HashAlgo.getInstance(requestOptions.getHashAlgorithmId()); if (hashAlgo == null) { throw new OcspRequestorException("unknown HashAlgo " DEROctetString issuerNameHash = new DEROctetString(hashAlgo.hash( caCert.getSubjectX500Principal().getEncoded())); throw new OcspRequestorException(ex); DEROctetString issuerKeyHash = new DEROctetString(hashAlgo.hash( tbsCert.getSubjectPublicKeyInfo().getPublicKeyData().getOctets())); CertID certId = new CertID(hashAlgo.getAlgorithmIdentifier(), issuerNameHash, issuerKeyHash, new ASN1Integer(serialNumber));
public static HashAlgo getNonNullInstance(String nameOrOid) { HashAlgo type = getInstance(nameOrOid); if (type == null) { throw new IllegalArgumentException("Unknown HashAlgo OID/name '" + nameOrOid + "'"); } return type; }
PbmMacCmpResponder(X500Name x500Name, List<String> owfs, List<String> macs) { super(x500Name); this.owfAlgos = new ArrayList<>(owfs.size()); for (int i = 0; i < owfs.size(); i++) { String algo = owfs.get(i); HashAlgo ha; try { ha = HashAlgo.getNonNullInstance(algo); } catch (Exception ex) { throw new IllegalArgumentException("invalid owf " + algo, ex); } owfAlgos.add(ha.getOid()); } this.macAlgos = new ArrayList<>(macs.size()); for (int i = 0; i < macs.size(); i++) { String algo = macs.get(i); AlgorithmIdentifier algId; try { algId = AlgorithmUtil.getMacAlgId(algo); } catch (NoSuchAlgorithmException ex) { throw new IllegalArgumentException("invalid mac" + algo, ex); } macAlgos.add(algId.getAlgorithm()); } }
@Override protected Object execute0() throws Exception { Certificate cert = X509Util.parseBcCert(IoUtil.read(inFile)); if (serial != null && serial) { return getNumber(cert.getSerialNumber().getPositiveValue()); } else if (subject != null && subject) { return cert.getSubject().toString(); } else if (issuer != null && issuer) { return cert.getIssuer().toString(); } else if (notBefore != null && notBefore) { return toUtcTimeyyyyMMddhhmmssZ(cert.getStartDate().getDate()); } else if (notAfter != null && notAfter) { return toUtcTimeyyyyMMddhhmmssZ(cert.getEndDate().getDate()); } else if (fingerprint != null && fingerprint) { byte[] encoded = cert.getEncoded(); return HashAlgo.getInstance(hashAlgo).hexHash(encoded); } return null; }
CmpClientConf.Requestor.PbmMac cf = requestorConf.getPbmMac(); X500Name x500name = new X500Name(cf.getSender()); AlgorithmIdentifier owf = HashAlgo.getNonNullInstance(cf.getOwf()).getAlgorithmIdentifier(); AlgorithmIdentifier mac; try {
@Override protected byte[] digestSecretKey0(long mechanism) throws P11TokenException { if (!(signingKey instanceof SecretKey)) { throw new P11TokenException("digestSecretKey could not be applied to non-SecretKey"); } HashAlgo hashAlgo = getHashAlgoForPkcs11HashMech(mechanism); if (hashAlgo == null) { throw new P11TokenException( "unknown mechanism " + Functions.mechanismCodeToString(mechanism)); } return hashAlgo.hash(((SecretKey) signingKey).getEncoded()); }
private static Digest getDigest(AlgorithmIdentifier hashAlgo) throws XiSecurityException { HashAlgo hat = HashAlgo.getInstance(hashAlgo.getAlgorithm()); if (hat != null) { return hat.createDigest(); } else { throw new XiSecurityException("could not get digest for " + hashAlgo.getAlgorithm().getId()); } }
private String base64Fp(byte[] data) { return HashAlgo.SHA1.base64Hash(data); }
private static void addHashAlgoNameMap(Map<ASN1ObjectIdentifier, String> oidNameMap, Map<String, HashAlgo> nameOidMap, HashAlgo hashAlgo, String... names) { oidNameMap.put(hashAlgo.getOid(), names[0].toUpperCase()); nameOidMap.put(hashAlgo.getOid().getId(), hashAlgo); for (String name : names) { nameOidMap.put(name.toUpperCase(), hashAlgo); } }
/** * mask generator function, as described in PKCS1v2. */ // CHECKSTYLE:SKIP private static byte[] maskGeneratorFunction1(HashAlgo mgfDigest, byte[] Z, int length) { int mgfhLen = mgfDigest.getLength(); byte[] mask = new byte[length]; int counter = 0; byte[] all = new byte[Z.length + 4]; System.arraycopy(Z, 0, all, 0, Z.length); while (counter < (length / mgfhLen)) { ItoOSP(counter, all, Z.length); byte[] hashBuf = mgfDigest.hash(all); System.arraycopy(hashBuf, 0, mask, counter * mgfhLen, mgfhLen); counter++; } if ((counter * mgfhLen) < length) { ItoOSP(counter, all, Z.length); byte[] hashBuf = mgfDigest.hash(all); int offset = counter * mgfhLen; System.arraycopy(hashBuf, 0, mask, offset, mask.length - offset); } return mask; }
private static RSASSAPSSparams createPSSRSAParams(HashAlgo digestAlg) throws NoSuchAlgorithmException { int saltSize = Args.notNull(digestAlg, "digestAlg").getLength(); AlgorithmIdentifier digAlgId = new AlgorithmIdentifier(digestAlg.getOid(), DERNull.INSTANCE); return new RSASSAPSSparams(digAlgId, new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, digAlgId), new ASN1Integer(saltSize), RSASSAPSSparams.DEFAULT_TRAILER_FIELD); } // method createPSSRSAParams
public String toString(boolean verbose, boolean ignoreSensitiveInfo) { String conf = getConf(); if (ignoreSensitiveInfo) { conf = eraseSensitiveData(conf); } StringBuilder sb = new StringBuilder(conf.length() + 50); sb.append("conf: "); sb.append(conf); if (hashAlgo != null) { sb.append("\nhash algo: ").append(hashAlgo.getName()); } if (signatureAlgoControl != null) { sb.append("\nsiganture algo control: ").append(signatureAlgoControl); } return sb.toString(); }
HashAlgo ha; try { ha = HashAlgo.getNonNullInstance(algo); } catch (Exception ex) { throw new InvalidConfException("invalid pbmPwf " + algo, ex); canonicalizedAlgos.add(ha.getName()); requestPbmOwfs.add(ha.getOid()); responsePbmOwf = ha.getAlgorithmIdentifier();