private MacData( ASN1Sequence seq) { this.digInfo = DigestInfo.getInstance(seq.getObjectAt(0)); this.salt = ((ASN1OctetString)seq.getObjectAt(1)).getOctets(); if (seq.size() == 3) { this.iterationCount = ((ASN1Integer)seq.getObjectAt(2)).getValue(); } else { this.iterationCount = ONE; } }
public static Data getInstance(Object obj) { if (obj instanceof Data) { return (Data)obj; } else if (obj instanceof ASN1OctetString) { return new Data((ASN1OctetString)obj); } else if (obj instanceof ASN1Sequence) { return new Data(DigestInfo.getInstance(obj)); } else if (obj instanceof ASN1TaggedObject) { return new Data(ASN1Sequence.getInstance((ASN1TaggedObject)obj, false)); } throw new IllegalArgumentException("Unknown object submitted to getInstance: " + obj.getClass().getName()); }
public DVCSCertInfo( DVCSRequestInformation dvReqInfo, DigestInfo messageImprint, ASN1Integer serialNumber, DVCSTime responseTime) { this.dvReqInfo = dvReqInfo; this.messageImprint = messageImprint; this.serialNumber = serialNumber; this.responseTime = responseTime; }
/** * constructor */ private OtherCertID(ASN1Sequence seq) { if (seq.size() < 1 || seq.size() > 2) { throw new IllegalArgumentException("Bad sequence size: " + seq.size()); } if (seq.getObjectAt(0).toASN1Primitive() instanceof ASN1OctetString) { otherCertHash = ASN1OctetString.getInstance(seq.getObjectAt(0)); } else { otherCertHash = DigestInfo.getInstance(seq.getObjectAt(0)); } if (seq.size() > 1) { issuerSerial = IssuerSerial.getInstance(seq.getObjectAt(1)); } }
public MessageImprint build(byte[] message) throws DVCSException { try { OutputStream dOut = digestCalculator.getOutputStream(); dOut.write(message); dOut.close(); return new MessageImprint(new DigestInfo(digestCalculator.getAlgorithmIdentifier(), digestCalculator.getDigest())); } catch (Exception e) { throw new DVCSException("unable to build MessageImprint: " + e.getMessage(), e); } }
public MacData( ASN1Sequence seq) { this.digInfo = DigestInfo.getInstance(seq.getObjectAt(0)); this.salt = ((ASN1OctetString)seq.getObjectAt(1)).getOctets(); if (seq.size() == 3) { this.iterationCount = ((DERInteger)seq.getObjectAt(2)).getValue(); } else { this.iterationCount = BigInteger.valueOf(1); } }
@Test @QualityAssurance(firmware = Firmware.V015Z, approved = true) public void testPlainTextAuthn() throws Exception { // operate String testMessage = "Test Application @ 14/2/2012 14:48:21"; byte[] signatureValue = this.pcscEid.sign(testMessage.getBytes(), "2.16.56.1.2.1.3.1", (byte) 0x82, false); // verify List<X509Certificate> authnCertChain = this.pcscEid.getAuthnCertificateChain(); Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); cipher.init(Cipher.DECRYPT_MODE, authnCertChain.get(0)); byte[] signatureDigestInfoValue = cipher.doFinal(signatureValue); ASN1InputStream aIn = new ASN1InputStream(signatureDigestInfoValue); DigestInfo signatureDigestInfo = new DigestInfo((ASN1Sequence) aIn.readObject()); LOG.debug("result algo Id: " + signatureDigestInfo.getAlgorithmId().getObjectId().getId()); assertEquals("2.16.56.1.2.1.3.1", signatureDigestInfo.getAlgorithmId().getObjectId().getId()); assertArrayEquals(testMessage.getBytes(), signatureDigestInfo.getDigest()); }
private boolean __verifyNonRepSignature(final byte[] expectedDigestValue, final byte[] signatureValue, final X509Certificate certificate) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, IOException { final PublicKey publicKey = certificate.getPublicKey(); final Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.DECRYPT_MODE, publicKey); final byte[] actualSignatureDigestInfoValue = cipher.doFinal(signatureValue); final ASN1InputStream asnInputStream = new ASN1InputStream(actualSignatureDigestInfoValue); final DigestInfo actualSignatureDigestInfo = new DigestInfo((ASN1Sequence) asnInputStream.readObject()); asnInputStream.close(); final byte[] actualDigestValue = actualSignatureDigestInfo.getDigest(); return Arrays.equals(expectedDigestValue, actualDigestValue); }
/** * Compute the content proxy for a given node. This should likely move somewhere else * @param nodeContent the content stored at this node * @param isDigest is the content already digested * @return the proxy digest (for example, the computed root of the Merkle hash tree) for this node * @throws CertificateEncodingException if we cannot decode the witness */ public byte[] computeProxy(byte[] nodeContent, boolean isDigest) throws CertificateEncodingException { if (null == witness()) return null; DigestInfo info = CCNDigestHelper.digestDecoder(witness()); byte [] proxy = null; if (MerklePath.isMerklePath(info)) { MerklePath mp = new MerklePath(info.getDigest()); proxy = mp.root(nodeContent, isDigest); } else { Log.warning("Unexpected witness type: " + info.getAlgorithmId().toString()); } return proxy; }
public MacData build(char[] password, byte[] data) throws PKCSException { MacCalculator macCalculator; try { macCalculator = builder.build(password); OutputStream out = macCalculator.getOutputStream(); out.write(data); out.close(); } catch (Exception e) { throw new PKCSException("unable to process data: " + e.getMessage(), e); } AlgorithmIdentifier algId = macCalculator.getAlgorithmIdentifier(); DigestInfo dInfo = new DigestInfo(builder.getDigestAlgorithmIdentifier(), macCalculator.getMac()); PKCS12PBEParams params = PKCS12PBEParams.getInstance(algId.getParameters()); return new MacData(dInfo, params.getIV(), params.getIterations().intValue()); }
private byte[] derEncode( byte[] hash) throws IOException { DigestInfo dInfo = new DigestInfo(algId, hash); return dInfo.getEncoded(ASN1Encoding.DER); }
public MacData( DigestInfo digInfo, byte[] salt, int iterationCount) { this.digInfo = digInfo; this.salt = salt; this.iterationCount = BigInteger.valueOf(iterationCount); }
public DVCSCertInfoBuilder( DVCSRequestInformation dvReqInfo, DigestInfo messageImprint, ASN1Integer serialNumber, DVCSTime responseTime) { this.dvReqInfo = dvReqInfo; this.messageImprint = messageImprint; this.serialNumber = serialNumber; this.responseTime = responseTime; }
public OtherCertID( AlgorithmIdentifier algId, byte[] digest, IssuerSerial issuerSerial) { this.otherCertHash = new DigestInfo(algId, digest); this.issuerSerial = issuerSerial; }
public AlgorithmIdentifier getAlgorithmHash() { if (otherCertHash.toASN1Primitive() instanceof ASN1OctetString) { // SHA-1 return new AlgorithmIdentifier("1.3.14.3.2.26"); } else { return DigestInfo.getInstance(otherCertHash).getAlgorithmId(); } }
public byte[] getCertHash() { if (otherCertHash.toASN1Primitive() instanceof ASN1OctetString) { // SHA-1 return ((ASN1OctetString)otherCertHash.toASN1Primitive()).getOctets(); } else { return DigestInfo.getInstance(otherCertHash).getDigest(); } }
private byte[] derEncode( byte[] hash) throws IOException { if (algId == null) { // For raw RSA, the DigestInfo must be prepared externally return hash; } DigestInfo dInfo = new DigestInfo(algId, hash); return dInfo.getEncoded(ASN1Encoding.DER); }