private KeyTransRecipientInfo computeRecipientInfo(X509Certificate x509certificate, byte[] abyte0) throws IOException, CertificateEncodingException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { TBSCertificate certificate; try (ASN1InputStream input = new ASN1InputStream(x509certificate.getTBSCertificate())) { certificate = TBSCertificate.getInstance(input.readObject()); } AlgorithmIdentifier algorithmId = certificate.getSubjectPublicKeyInfo().getAlgorithm(); IssuerAndSerialNumber serial = new IssuerAndSerialNumber( certificate.getIssuer(), certificate.getSerialNumber().getValue()); Cipher cipher; try { cipher = Cipher.getInstance(algorithmId.getAlgorithm().getId(), SecurityProvider.getProvider()); } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { // should never happen, if this happens throw IOException instead throw new RuntimeException("Could not find a suitable javax.crypto provider", e); } cipher.init(1, x509certificate.getPublicKey()); DEROctetString octets = new DEROctetString(cipher.doFinal(abyte0)); RecipientIdentifier recipientId = new RecipientIdentifier(serial); return new KeyTransRecipientInfo(recipientId, algorithmId, octets); }
private ASN1ObjectIdentifier getAlgorithmId(ASN1Object keyInfo) { if (keyInfo instanceof PrivateKeyInfo) { return ((PrivateKeyInfo) keyInfo).getPrivateKeyAlgorithm().getAlgorithm(); } else if (keyInfo instanceof SubjectPublicKeyInfo) { return ((SubjectPublicKeyInfo) keyInfo).getAlgorithm().getAlgorithm(); } else { throw new IllegalArgumentException("Asymmetric key expected but received: " + keyInfo.getClass().getName()); } }
public PublicKey generatePublic(SubjectPublicKeyInfo keyInfo) throws IOException { ASN1ObjectIdentifier algOid = keyInfo.getAlgorithm().getAlgorithm(); if (DSAUtil.isDsaOid(algOid)) { return new BCDSAPublicKey(keyInfo); } else { throw new IOException("algorithm identifier " + algOid + " in key not recognised"); } }
public static PublicKey getPublicKey(SubjectPublicKeyInfo publicKeyInfo) throws IOException { AsymmetricKeyInfoConverter converter = getAsymmetricKeyInfoConverter(publicKeyInfo.getAlgorithm().getAlgorithm()); if (converter == null) { return null; } return converter.generatePublic(publicKeyInfo); }
public static PublicKey getPublicKey(SubjectPublicKeyInfo publicKeyInfo) throws IOException { AsymmetricKeyInfoConverter converter = getAsymmetricKeyInfoConverter(publicKeyInfo.getAlgorithm().getAlgorithm()); if (converter == null) { return null; } return converter.generatePublic(publicKeyInfo); }
AsymmetricKeyParameter getPublicKeyParameters(SubjectPublicKeyInfo keyInfo, Object defaultParams) throws IOException { return new QTESLAPublicKeyParameters(Utils.qTeslaLookupSecurityCategory(keyInfo.getAlgorithm()), keyInfo.getPublicKeyData().getOctets()); } }
public static boolean hasGOSTParameters(Certificate cert) { if (cert.isEmpty()) { return false; } SubjectPublicKeyInfo keyInfo = cert.getCertificateAt(0).getSubjectPublicKeyInfo(); return keyInfo.getAlgorithm().getAlgorithm().equals(CryptoProObjectIdentifiers.gostR3410_94); }
public static boolean hasGost01EcParameters(Certificate cert) { if (cert.isEmpty()) { return false; } SubjectPublicKeyInfo keyInfo = cert.getCertificateAt(0).getSubjectPublicKeyInfo(); ASN1ObjectIdentifier alg = keyInfo.getAlgorithm().getAlgorithm(); return alg.equals(CryptoProObjectIdentifiers.gostR3410_2001); }
public static boolean hasDHParameters(Certificate cert) { if (cert.isEmpty()) { return false; } SubjectPublicKeyInfo keyInfo = cert.getCertificateAt(0).getSubjectPublicKeyInfo(); return keyInfo.getAlgorithm().getAlgorithm().equals(X9ObjectIdentifiers.dhpublicnumber); }
public static boolean hasECParameters(Certificate cert) { if (cert.isEmpty()) { return false; } SubjectPublicKeyInfo keyInfo = cert.getCertificateAt(0).getSubjectPublicKeyInfo(); if (keyInfo == null) { return false; } return keyInfo.getAlgorithm().getAlgorithm().equals(X9ObjectIdentifiers.id_ecPublicKey); }
private void init(SubjectPublicKeyInfo keyInfo) throws IOException { XMSSMTKeyParams keyParams = XMSSMTKeyParams.getInstance(keyInfo.getAlgorithm().getParameters()); this.treeDigest = keyParams.getTreeDigest().getAlgorithm(); this.keyParams = (XMSSMTPublicKeyParameters)PublicKeyFactory.createKey(keyInfo); }
private void init(SubjectPublicKeyInfo keyInfo) throws IOException { this.treeDigest = SPHINCS256KeyParams.getInstance(keyInfo.getAlgorithm().getParameters()).getTreeDigest().getAlgorithm(); this.params = (SPHINCSPublicKeyParameters)PublicKeyFactory.createKey(keyInfo); }
private void init(SubjectPublicKeyInfo keyInfo) throws IOException { XMSSKeyParams keyParams = XMSSKeyParams.getInstance(keyInfo.getAlgorithm().getParameters()); this.treeDigest = keyParams.getTreeDigest().getAlgorithm(); this.keyParams = (XMSSPublicKeyParameters)PublicKeyFactory.createKey(keyInfo); }
public static boolean hasGost12EcParameters(Certificate cert) { if (cert.isEmpty()) { return false; } SubjectPublicKeyInfo keyInfo = cert.getCertificateAt(0).getSubjectPublicKeyInfo(); ASN1ObjectIdentifier alg = keyInfo.getAlgorithm().getAlgorithm(); return alg.equals(RosstandartObjectIdentifiers.id_tc26_gost_3410_12_256) || alg.equals(RosstandartObjectIdentifiers.id_tc26_gost_3410_12_512); }
AsymmetricKeyParameter getPublicKeyParameters(SubjectPublicKeyInfo keyInfo, Object defaultParams) throws IOException { return new SPHINCSPublicKeyParameters(keyInfo.getPublicKeyData().getBytes(), Utils.sphincs256LookupTreeAlgName(SPHINCS256KeyParams.getInstance(keyInfo.getAlgorithm().getParameters()))); } }
AsymmetricKeyParameter getPublicKeyParameters(SubjectPublicKeyInfo keyInfo, Object defaultParams) throws IOException { DHParameter params = DHParameter.getInstance(keyInfo.getAlgorithm().getParameters()); ASN1Integer derY = (ASN1Integer)keyInfo.parsePublicKey(); BigInteger lVal = params.getL(); int l = lVal == null ? 0 : lVal.intValue(); DHParameters dhParams = new DHParameters(params.getP(), params.getG(), null, l); return new DHPublicKeyParameters(derY.getValue(), dhParams); } }
private void populateFromPubKeyInfo(SubjectPublicKeyInfo keyInfo) { if (EdECObjectIdentifiers.id_X448.equals(keyInfo.getAlgorithm().getAlgorithm())) { xdhPublicKey = new X448PublicKeyParameters(keyInfo.getPublicKeyData().getOctets(), 0); } else { xdhPublicKey = new X25519PublicKeyParameters(keyInfo.getPublicKeyData().getOctets(), 0); } }
private void populateFromPubKeyInfo(SubjectPublicKeyInfo keyInfo) { if (EdECObjectIdentifiers.id_Ed448.equals(keyInfo.getAlgorithm().getAlgorithm())) { eddsaPublicKey = new Ed448PublicKeyParameters(keyInfo.getPublicKeyData().getOctets(), 0); } else { eddsaPublicKey = new Ed25519PublicKeyParameters(keyInfo.getPublicKeyData().getOctets(), 0); } }
AsymmetricKeyParameter getPublicKeyParameters(SubjectPublicKeyInfo keyInfo, Object defaultParams) throws IOException { ElGamalParameter params = ElGamalParameter.getInstance(keyInfo.getAlgorithm().getParameters()); ASN1Integer derY = (ASN1Integer)keyInfo.parsePublicKey(); return new ElGamalPublicKeyParameters(derY.getValue(), new ElGamalParameters( params.getP(), params.getG())); } }
AsymmetricKeyParameter getPublicKeyParameters(SubjectPublicKeyInfo keyInfo, Object defaultParams) throws IOException { XMSSKeyParams keyParams = XMSSKeyParams.getInstance(keyInfo.getAlgorithm().getParameters()); ASN1ObjectIdentifier treeDigest = keyParams.getTreeDigest().getAlgorithm(); XMSSPublicKey xmssPublicKey = XMSSPublicKey.getInstance(keyInfo.parsePublicKey()); return new XMSSPublicKeyParameters .Builder(new XMSSParameters(keyParams.getHeight(), Utils.getDigest(treeDigest))) .withPublicSeed(xmssPublicKey.getPublicSeed()) .withRoot(xmssPublicKey.getRoot()).build(); } }