public PublicKey getPublicCAKey() throws InvalidKeySpecException, IOException, NoSuchAlgorithmException, NoSuchProviderException { ChipAuthenticationPublicKeyInfo info = securityInfos.getDefaultChipAuthenticationPublicKeyInfo(); AlgorithmParameterSpec algorithmParameterSpec = securityInfos.getDefaultCADomainParameter().getAlgorithmParameterSpec(); Type type = securityInfos.getDefaultCADomainParameter().getType(); PublicKey pubKey = null; if (type == Type.ECDH) { ECParameterSpec eps = (ECParameterSpec) algorithmParameterSpec; DEROctetString dos = new DEROctetString(info.getSubjectPublicKeyInfo().getPublicKeyData().getBytes()); ECPoint point = new X9ECPoint(eps.getCurve(), dos).getPoint(); ECPublicKeySpec eks = new ECPublicKeySpec(point, eps); pubKey = new JCEECPublicKey(type.toString(), eks); } else { DHParameterSpec dps = (DHParameterSpec) algorithmParameterSpec; ASN1Integer dos = new ASN1Integer(info.getSubjectPublicKeyInfo().getPublicKeyData().getBytes()); DHPublicKeySpec keySpec = new DHPublicKeySpec(dos.getPositiveValue(), dps.getP(), dps.getG()); KeyFactory kf = KeyFactory.getInstance(type.toString()); return kf.generatePublic(keySpec); } return pubKey; }
public void fromAsn1(byte[] data, int defaultCAKeyID) throws IOException, EIDException { try { ASN1InputStream ais = new ASN1InputStream(data); try { ASN1Sequence seq = (ASN1Sequence) ais.readObject(); ContentInfo ci = ContentInfo.getInstance(seq); if (!ci.getContentType().equals(CMSObjectIdentifiers.signedData)) throw new EIDException("wrong content type in CardSecurity"); SignedData sd = SignedData.getInstance((ASN1Sequence) ci.getContent()); ContentInfo eci = sd.getEncapContentInfo(); if (!eci.getContentType().equals(EAC2ObjectIdentifiers.id_SecurityObject)) throw new EIDException("CardSecurity does not encapsulate SecurityInfos"); SecurityInfos si = new SecurityInfos(); si.fromAsn1(((ASN1OctetString) eci.getContent()).getOctets(), defaultCAKeyID); securityInfos = si; } finally { ais.close(); } } catch (Exception e) { throw new EIDException(e); } }
public DHDomainParameter.Type getCAAlgorithmType() { return securityInfos.getDefaultCADomainParameter().getType(); }