Tabnine Logo
CryptoPrimitives
Code IndexAdd Tabnine to your IDE (free)

How to use
CryptoPrimitives
in
org.hyperledger.fabric.sdk.security

Best Java code snippets using org.hyperledger.fabric.sdk.security.CryptoPrimitives (Showing top 20 results out of 315)

origin: hyperledger/fabric-sdk-java

  cryptoPrimitives = new CryptoPrimitives();
  cryptoPrimitives.init();
} catch (Exception e) {
  throw new InvalidArgumentException(e);
      cryptoPrimitives.addCACertificatesToTrustStore(bis);
            try (BufferedInputStream bis = new BufferedInputStream(
                new ByteArrayInputStream(Files.readAllBytes(Paths.get(pem))))) {
              cryptoPrimitives.addCACertificatesToTrustStore(bis);
      .loadTrustMaterial(cryptoPrimitives.getTrustStore(), null)
      .build();
  if (null != properties &&
      "true".equals(properties.getProperty("allowAllHostNames"))) {
    AllHostsSSLSocketFactory msf = new AllHostsSSLSocketFactory(cryptoPrimitives.getTrustStore());
    msf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    sf = msf;
origin: hyperledger/fabric-sdk-java

private void addCACertificateToTrustStore(Certificate certificate) throws InvalidArgumentException, CryptoException {
  String alias;
  if (certificate instanceof X509Certificate) {
    alias = ((X509Certificate) certificate).getSerialNumber().toString();
  } else { // not likely ...
    alias = Integer.toString(certificate.hashCode());
  }
  addCACertificateToTrustStore(certificate, alias);
}
origin: hyperledger/fabric-sdk-java

  cp = new CryptoPrimitives();
} catch (Exception e) {
  throw new RuntimeException(e);
whatBytes = ckb;
logger.trace("client TLS key bytes:" + Hex.encodeHexString(ckb));
PrivateKey clientKey = cp.bytesToPrivateKey(ckb);
logger.trace("converted TLS key.");
what = "certificate";
whatBytes = ccb;
logger.trace("client TLS certificate bytes:" + Hex.encodeHexString(ccb));
X509Certificate[] clientCert = new X509Certificate[] {(X509Certificate) cp.bytesToCertificate(ccb)};
logger.trace("converted client TLS certificate.");
origin: hyperledger/fabric-sdk-java

@Override
public void loadCACertificatesAsBytes(Collection<byte[]> certificatesBytes) throws CryptoException {
  if (certificatesBytes == null || certificatesBytes.size() == 0) {
    throw new CryptoException("List of CA certificates is empty. Nothing to load.");
  }
  ArrayList<Certificate> certList = new ArrayList<>();
  for (byte[] certBytes : certificatesBytes) {
    certList.add(bytesToCertificate(certBytes));
  }
  loadCACertificates(certList);
}
origin: hyperledger/fabric-sdk-java

@Override
public CryptoSuite getCryptoSuite(Properties properties) throws CryptoException, InvalidArgumentException {
  CryptoSuite ret = cache.get(properties);
  if (ret == null) {
    try {
      CryptoPrimitives cp = new CryptoPrimitives();
      cp.setProperties(properties);
      cp.init();
      ret = cp;
    } catch (Exception e) {
      throw new CryptoException(e.getMessage(), e);
    }
    cache.put(properties, ret);
  }
  return ret;
}
origin: hyperledger/fabric-sdk-java

byte[] signature = sig.sign();
BigInteger[] sigs = decodeECDSASignature(signature);
sigs = preventMalleability(sigs, curveN);
origin: hyperledger/fabric-sdk-java

@Override
public KeyPair keyGen() throws CryptoException {
  return ecdsaKeyGen();
}
origin: hyperledger/fabric-sdk-java

/**
 * getTrustStore returns the KeyStore object where we keep trusted certificates.
 * If no trust store has been set, this method will create one.
 *
 * @return the trust store as a java.security.KeyStore object
 * @throws CryptoException
 * @see KeyStore
 */
public KeyStore getTrustStore() throws CryptoException {
  if (trustStore == null) {
    createTrustStore();
  }
  return trustStore;
}
origin: hyperledger/fabric-sdk-java

/**
 * generateCertificationRequest
 *
 * @param subject The subject to be added to the certificate
 * @param pair    Public private key pair
 * @return PKCS10CertificationRequest Certificate Signing Request.
 * @throws OperatorCreationException
 */
public String generateCertificationRequest(String subject, KeyPair pair)
    throws InvalidArgumentException {
  try {
    PKCS10CertificationRequestBuilder p10Builder = new JcaPKCS10CertificationRequestBuilder(
        new X500Principal("CN=" + subject), pair.getPublic());
    JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder("SHA256withECDSA");
    if (null != SECURITY_PROVIDER) {
      csBuilder.setProvider(SECURITY_PROVIDER);
    }
    ContentSigner signer = csBuilder.build(pair.getPrivate());
    return certificationRequestToPEM(p10Builder.build(signer));
  } catch (Exception e) {
    logger.error(e);
    throw new InvalidArgumentException(e);
  }
}
origin: hyperledger/fabric-sdk-java

byte[] der = cp.certificateToDER(cert);
if (null != der && der.length > 0) {
origin: com.impetus.fabric/fabric-jdbc-driver-shaded

@Override
public CryptoSuite getCryptoSuite(Properties properties) throws CryptoException, InvalidArgumentException {
  CryptoSuite ret = cache.get(properties);
  if (ret == null) {
    try {
      CryptoPrimitives cp = new CryptoPrimitives();
      cp.setProperties(properties);
      cp.init();
      ret = cp;
    } catch (Exception e) {
      throw new CryptoException(e.getMessage(), e);
    }
    cache.put(properties, ret);
  }
  return ret;
}
origin: org.hyperledger.fabric-sdk-java/fabric-sdk-java

@Override
public void loadCACertificatesAsBytes(Collection<byte[]> certificatesBytes) throws CryptoException {
  if (certificatesBytes == null || certificatesBytes.size() == 0) {
    throw new CryptoException("List of CA certificates is empty. Nothing to load.");
  }
  ArrayList<Certificate> certList = new ArrayList<>();
  for (byte[] certBytes : certificatesBytes) {
    certList.add(bytesToCertificate(certBytes));
  }
  loadCACertificates(certList);
}
origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * Sign data with the specified elliptic curve private key.
 *
 * @param privateKey elliptic curve private key.
 * @param data       data to sign
 * @return the signed data.
 * @throws CryptoException
 */
private byte[] ecdsaSignToBytes(ECPrivateKey privateKey, byte[] data) throws CryptoException {
  try {
    X9ECParameters params = ECNamedCurveTable.getByName(curveName);
    BigInteger curveN = params.getN();
    Signature sig = SECURITY_PROVIDER == null ? Signature.getInstance(DEFAULT_SIGNATURE_ALGORITHM) :
        Signature.getInstance(DEFAULT_SIGNATURE_ALGORITHM, SECURITY_PROVIDER);
    sig.initSign(privateKey);
    sig.update(data);
    byte[] signature = sig.sign();
    BigInteger[] sigs = decodeECDSASignature(signature);
    sigs = preventMalleability(sigs, curveN);
    try (ByteArrayOutputStream s = new ByteArrayOutputStream()) {
      DERSequenceGenerator seq = new DERSequenceGenerator(s);
      seq.addObject(new ASN1Integer(sigs[0]));
      seq.addObject(new ASN1Integer(sigs[1]));
      seq.close();
      return s.toByteArray();
    }
  } catch (Exception e) {
    throw new CryptoException("Could not sign the message using private key", e);
  }
}
origin: org.hyperledger.fabric-sdk-java/fabric-sdk-java

@Override
public KeyPair keyGen() throws CryptoException {
  return ecdsaKeyGen();
}
origin: org.hyperledger.fabric-sdk-java/fabric-sdk-java

/**
 * getTrustStore returns the KeyStore object where we keep trusted certificates.
 * If no trust store has been set, this method will create one.
 *
 * @return the trust store as a java.security.KeyStore object
 * @throws CryptoException
 * @see KeyStore
 */
public KeyStore getTrustStore() throws CryptoException {
  if (trustStore == null) {
    createTrustStore();
  }
  return trustStore;
}
origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * generateCertificationRequest
 *
 * @param subject The subject to be added to the certificate
 * @param pair    Public private key pair
 * @return PKCS10CertificationRequest Certificate Signing Request.
 * @throws OperatorCreationException
 */
public String generateCertificationRequest(String subject, KeyPair pair)
    throws InvalidArgumentException {
  try {
    PKCS10CertificationRequestBuilder p10Builder = new JcaPKCS10CertificationRequestBuilder(
        new X500Principal("CN=" + subject), pair.getPublic());
    JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder("SHA256withECDSA");
    if (null != SECURITY_PROVIDER) {
      csBuilder.setProvider(SECURITY_PROVIDER);
    }
    ContentSigner signer = csBuilder.build(pair.getPrivate());
    return certificationRequestToPEM(p10Builder.build(signer));
  } catch (Exception e) {
    logger.error(e);
    throw new InvalidArgumentException(e);
  }
}
origin: org.hyperledger.fabric-sdk-java/fabric-sdk-java

byte[] der = cp.certificateToDER(cert);
if (null != der && der.length > 0) {
origin: org.hyperledger.fabric-sdk-java/fabric-sdk-java

  cryptoPrimitives = new CryptoPrimitives();
  cryptoPrimitives.init();
} catch (Exception e) {
  throw new InvalidArgumentException(e);
      cryptoPrimitives.addCACertificatesToTrustStore(bis);
            try (BufferedInputStream bis = new BufferedInputStream(
                new ByteArrayInputStream(Files.readAllBytes(Paths.get(pem))))) {
              cryptoPrimitives.addCACertificatesToTrustStore(bis);
      .loadTrustMaterial(cryptoPrimitives.getTrustStore(), null)
      .build();
  if (null != properties &&
      "true".equals(properties.getProperty("allowAllHostNames"))) {
    AllHostsSSLSocketFactory msf = new AllHostsSSLSocketFactory(cryptoPrimitives.getTrustStore());
    msf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    sf = msf;
origin: hyperledger/fabric-sdk-java

CryptoPrimitives cp;
try {
  cp = new CryptoPrimitives();
} catch (Exception e) {
  throw new RuntimeException(e);
      if (cn == null) {
        X500Name x500name = new JcaX509CertificateHolder(
            (X509Certificate) cp.bytesToCertificate(pemBytes)).getSubject();
        RDN rdn = x500name.getRDNs(BCStyle.CN)[0];
        cn = IETFUtils.valueToString(rdn.getFirst().getValue());
    whatBytes = ckb;
    logger.trace("client TLS key bytes:" + Hex.encodeHexString(ckb));
    clientKey = cp.bytesToPrivateKey(ckb);
    logger.trace("converted TLS key.");
    what = "certificate";
    whatBytes = ccb;
    logger.trace("client TLS certificate bytes:" + Hex.encodeHexString(ccb));
    clientCert = new X509Certificate[] {(X509Certificate) cp.bytesToCertificate(ccb)};
    logger.trace("converted client TLS certificate.");
origin: org.hyperledger.fabric-sdk-java/fabric-sdk-java

@Override
public CryptoSuite getCryptoSuite(Properties properties) throws CryptoException, InvalidArgumentException {
  CryptoSuite ret = cache.get(properties);
  if (ret == null) {
    try {
      CryptoPrimitives cp = new CryptoPrimitives();
      cp.setProperties(properties);
      cp.init();
      ret = cp;
    } catch (Exception e) {
      throw new CryptoException(e.getMessage(), e);
    }
    cache.put(properties, ret);
  }
  return ret;
}
org.hyperledger.fabric.sdk.securityCryptoPrimitives

Most used methods

  • <init>
  • addCACertificateToTrustStore
    addCACertificateToTrustStore adds a CA cert to the set of certificates used for signature validation
  • addCACertificatesToTrustStore
    addCACertificatesToTrustStore adds a CA certs in a stream to the trust store used for signature vali
  • bytesToCertificate
  • bytesToPrivateKey
    Return PrivateKey from pem bytes.
  • certificateToDER
  • certificationRequestToPEM
    certificationRequestToPEM - Convert a PKCS10CertificationRequest to PEM format.
  • createTrustStore
  • decodeECDSASignature
    Decodes an ECDSA signature and returns a two element BigInteger array.
  • ecdsaKeyGen
  • ecdsaSignToBytes
    Sign data with the specified elliptic curve private key.
  • generateKey
  • ecdsaSignToBytes,
  • generateKey,
  • getHashDigest,
  • getTrustStore,
  • getX509Certificate,
  • init,
  • loadCACertificates,
  • preventMalleability,
  • resetConfiguration,
  • setHashAlgorithm

Popular in Java

  • Running tasks concurrently on multiple threads
  • getSharedPreferences (Context)
  • findViewById (Activity)
  • getApplicationContext (Context)
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • String (java.lang)
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now