private byte[] getPlainSignature() throws XiSecurityException, P11TokenException { byte[] dataToSign; if (outputStream instanceof ByteArrayOutputStream) { dataToSign = ((ByteArrayOutputStream) outputStream).toByteArray(); ((ByteArrayOutputStream) outputStream).reset(); } else { dataToSign = ((DigestOutputStream) outputStream).digest(); ((DigestOutputStream) outputStream).reset(); } return cryptService.getIdentity(identityId).sign(mechanism, null, dataToSign); }
DSA(P11CryptService cryptService, P11IdentityId identityId, AlgorithmIdentifier signatureAlgId, boolean plain) throws XiSecurityException, P11TokenException { super(cryptService, identityId, signatureAlgId); this.plain = plain; String algOid = signatureAlgId.getAlgorithm().getId(); HashAlgo hashAlgo = sigAlgHashMap.get(algOid); if (hashAlgo == null) { throw new XiSecurityException("unsupported signature algorithm " + algOid); } P11SlotIdentifier slotId = identityId.getSlotId(); P11Slot slot = cryptService.getSlot(slotId); if (slot.supportsMechanism(PKCS11Constants.CKM_DSA)) { this.mechanism = PKCS11Constants.CKM_DSA; Digest digest = hashAlgo.createDigest(); this.outputStream = new DigestOutputStream(digest); } else { this.mechanism = hashMechMap.get(hashAlgo).longValue(); if (!slot.supportsMechanism(this.mechanism)) { throw new XiSecurityException("unsupported signature algorithm " + algOid); } this.outputStream = new ByteArrayOutputStream(); } }
@Override public OutputStream getOutputStream() { if (outputStream instanceof ByteArrayOutputStream) { ((ByteArrayOutputStream) outputStream).reset(); } else { ((DigestOutputStream) outputStream).reset(); } return outputStream; }
private byte[] getPlainSignature() throws XiSecurityException, P11TokenException { byte[] dataToSign; P11Params.P11ByteArrayParams params; if (outputStream instanceof ByteArrayOutputStream) { // dataToSign is the real message params = new P11Params.P11ByteArrayParams(GMUtil.getDefaultIDA()); dataToSign = ((ByteArrayOutputStream) outputStream).toByteArray(); } else { // dataToSign is Hash(Z||Real Message) params = null; dataToSign = ((DigestOutputStream) outputStream).digest(); } reset(); return cryptService.getIdentity(identityId).sign(mechanism, params, dataToSign); } }
ECDSA(P11CryptService cryptService, P11IdentityId identityId, AlgorithmIdentifier signatureAlgId, boolean plain) throws XiSecurityException, P11TokenException { super(cryptService, identityId, signatureAlgId); this.plain = plain; String algOid = signatureAlgId.getAlgorithm().getId(); HashAlgo hashAlgo = sigAlgHashMap.get(algOid); if (hashAlgo == null) { throw new XiSecurityException("unsupported signature algorithm " + algOid); } P11Slot slot = cryptService.getSlot(identityId.getSlotId()); if (slot.supportsMechanism(PKCS11Constants.CKM_ECDSA)) { this.mechanism = PKCS11Constants.CKM_ECDSA; Digest digest = hashAlgo.createDigest(); this.outputStream = new DigestOutputStream(digest); } else { this.mechanism = hashMechMap.get(hashAlgo).longValue(); if (!slot.supportsMechanism(this.mechanism)) { throw new XiSecurityException("unsupported signature algorithm " + algOid); } this.outputStream = new ByteArrayOutputStream(); } }
@Override public OutputStream getOutputStream() { if (outputStream instanceof ByteArrayOutputStream) { ((ByteArrayOutputStream) outputStream).reset(); } else { ((DigestOutputStream) outputStream).reset(); } return outputStream; }
private byte[] getPlainSignature() throws XiSecurityException, P11TokenException { byte[] dataToSign; P11ByteArrayParams params; if (outputStream instanceof ByteArrayOutputStream) { // dataToSign is the real message params = new P11ByteArrayParams(GMUtil.getDefaultIDA()); dataToSign = ((ByteArrayOutputStream) outputStream).toByteArray(); } else { // dataToSign is Hash(Z||Real Message) params = null; dataToSign = ((DigestOutputStream) outputStream).digest(); } reset(); return cryptService.getIdentity(identityId).sign(mechanism, params, dataToSign); } }
private byte[] getPlainSignature() throws XiSecurityException, P11TokenException { byte[] dataToSign; if (outputStream instanceof ByteArrayOutputStream) { dataToSign = ((ByteArrayOutputStream) outputStream).toByteArray(); ((ByteArrayOutputStream) outputStream).reset(); } else { dataToSign = ((DigestOutputStream) outputStream).digest(); ((DigestOutputStream) outputStream).reset(); } return cryptService.getIdentity(identityId).sign(mechanism, null, dataToSign); }
this.digestPkcsPrefix = SignerUtil.getDigestPkcsPrefix(hashAlgo); Digest digest = hashAlgo.createDigest(); this.outputStream = new DigestOutputStream(digest); } else { this.digestPkcsPrefix = null;
@Override public OutputStream getOutputStream() { if (outputStream instanceof ByteArrayOutputStream) { ((ByteArrayOutputStream) outputStream).reset(); } else { ((DigestOutputStream) outputStream).reset(); } return outputStream; }
@Override public byte[] getSignature() { if (outputStream instanceof PSSSignerOutputStream) { try { return ((PSSSignerOutputStream) outputStream).generateSignature(); } catch (CryptoException ex) { LogUtil.warn(LOG, ex); throw new RuntimeCryptoException("CryptoException: " + ex.getMessage()); } } byte[] dataToSign; if (outputStream instanceof ByteArrayOutputStream) { dataToSign = ((ByteArrayOutputStream) outputStream).toByteArray(); } else { dataToSign = ((DigestOutputStream) outputStream).digest(); } try { return cryptService.getIdentity(identityId).sign(mechanism, parameters, dataToSign); } catch (XiSecurityException | P11TokenException ex) { LogUtil.warn(LOG, ex, "could not sign"); throw new RuntimeCryptoException("SignerException: " + ex.getMessage()); } }
private byte[] getPlainSignature() throws XiSecurityException, P11TokenException { byte[] dataToSign; if (outputStream instanceof ByteArrayOutputStream) { dataToSign = ((ByteArrayOutputStream) outputStream).toByteArray(); ((ByteArrayOutputStream) outputStream).reset(); } else { dataToSign = ((DigestOutputStream) outputStream).digest(); ((DigestOutputStream) outputStream).reset(); } return cryptService.getIdentity(identityId).sign(mechanism, null, dataToSign); } }
SM2(P11CryptService cryptService, P11IdentityId identityId, AlgorithmIdentifier signatureAlgId, ASN1ObjectIdentifier curveOid, BigInteger pubPointX, BigInteger pubPointY) throws XiSecurityException, P11TokenException { super(cryptService, identityId, signatureAlgId); String algOid = signatureAlgId.getAlgorithm().getId(); HashAlgo hashAlgo = sigAlgHashMap.get(algOid); if (hashAlgo == null) { throw new XiSecurityException("unsupported signature algorithm " + algOid); } P11Slot slot = cryptService.getSlot(identityId.getSlotId()); if (slot.supportsMechanism(PKCS11Constants.CKM_VENDOR_SM2)) { this.z = GMUtil.getSM2Z(curveOid, pubPointX, pubPointY); this.mechanism = PKCS11Constants.CKM_VENDOR_SM2; Digest digest = hashAlgo.createDigest(); this.outputStream = new DigestOutputStream(digest); } else { this.z = null; // not required Long ll = hashMechMap.get(hashAlgo); if (ll == null) { throw new XiSecurityException("hash algorithm " + hashAlgo + " is not suitable for SM2"); } this.mechanism = ll.longValue(); if (!slot.supportsMechanism(this.mechanism)) { throw new XiSecurityException("unsupported signature algorithm " + algOid); } this.outputStream = new ByteArrayOutputStream(); } }
@Override public OutputStream getOutputStream() { if (outputStream instanceof ByteArrayOutputStream) { ((ByteArrayOutputStream) outputStream).reset(); } else { ((DigestOutputStream) outputStream).reset(); } return outputStream; }
@Override public byte[] getSignature() { if (outputStream instanceof PSSSignerOutputStream) { try { return ((PSSSignerOutputStream) outputStream).generateSignature(); } catch (CryptoException ex) { LogUtil.warn(LOG, ex); throw new RuntimeCryptoException("CryptoException: " + ex.getMessage()); } } byte[] dataToSign; if (outputStream instanceof ByteArrayOutputStream) { dataToSign = ((ByteArrayOutputStream) outputStream).toByteArray(); } else { dataToSign = ((DigestOutputStream) outputStream).digest(); } try { return cryptService.getIdentity(identityId).sign(mechanism, parameters, dataToSign); } catch (P11TokenException ex) { LogUtil.warn(LOG, ex, "could not sign"); throw new RuntimeCryptoException("SignerException: " + ex.getMessage()); } }
private byte[] getPlainSignature() throws XiSecurityException, P11TokenException { byte[] dataToSign; if (outputStream instanceof ByteArrayOutputStream) { dataToSign = ((ByteArrayOutputStream) outputStream).toByteArray(); ((ByteArrayOutputStream) outputStream).reset(); } else { dataToSign = ((DigestOutputStream) outputStream).digest(); ((DigestOutputStream) outputStream).reset(); } return cryptService.getIdentity(identityId).sign(mechanism, null, dataToSign); } }
outputStream = new ByteArrayOutputStream(); } else { outputStream = new DigestOutputStream(hashAlgo.createDigest());
@Override public OutputStream getOutputStream() { if (outputStream instanceof ByteArrayOutputStream) { ((ByteArrayOutputStream) outputStream).reset(); } else { ((DigestOutputStream) outputStream).reset(); } return outputStream; }
@Override public byte[] getSignature() { if (outputStream instanceof PSSSignerOutputStream) { try { return ((PSSSignerOutputStream) outputStream).generateSignature(); } catch (CryptoException ex) { LogUtil.warn(LOG, ex); throw new RuntimeCryptoException("CryptoException: " + ex.getMessage()); } } byte[] dataToSign; if (outputStream instanceof ByteArrayOutputStream) { dataToSign = ((ByteArrayOutputStream) outputStream).toByteArray(); } else { dataToSign = ((DigestOutputStream) outputStream).digest(); } try { return cryptService.getIdentity(identityId).sign(mechanism, parameters, dataToSign); } catch (P11TokenException ex) { LogUtil.warn(LOG, ex, "could not sign"); throw new RuntimeCryptoException("SignerException: " + ex.getMessage()); } }
private byte[] getPlainSignature() throws XiSecurityException, P11TokenException { byte[] dataToSign; if (outputStream instanceof ByteArrayOutputStream) { dataToSign = ((ByteArrayOutputStream) outputStream).toByteArray(); ((ByteArrayOutputStream) outputStream).reset(); } else { dataToSign = ((DigestOutputStream) outputStream).digest(); ((DigestOutputStream) outputStream).reset(); } return cryptService.getIdentity(identityId).sign(mechanism, null, dataToSign); }