public JcaDigestCalculatorProviderBuilder setProvider(String providerName) { this.helper = new OperatorHelper(new NamedJcaJceHelper(providerName)); return this; }
public ContentVerifierProvider build(SubjectPublicKeyInfo publicKey) throws OperatorCreationException { return this.build(helper.convertPublicKey(publicKey)); }
private Signature createRawSig(AlgorithmIdentifier algorithm, PublicKey publicKey) { Signature rawSig; try { rawSig = helper.createRawSignature(algorithm); if (rawSig != null) { rawSig.initVerify(publicKey); } } catch (Exception e) { rawSig = null; } return rawSig; }
public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey) throws OperatorException { GenericHybridParameters params = GenericHybridParameters.getInstance(this.getAlgorithmIdentifier().getParameters()); Cipher keyCipher = helper.createAsymmetricWrapper(this.getAlgorithmIdentifier().getAlgorithm(), extraMappings); String symmetricWrappingAlg = helper.getWrappingAlgorithmName(params.getDem().getAlgorithm()); RsaKemParameters kemParameters = RsaKemParameters.getInstance(params.getKem().getParameters()); int keySizeInBits = kemParameters.getKeyLength().intValue() * 8; Key sKey; try { DEROtherInfo otherInfo = new DEROtherInfo.Builder(params.getDem(), partyUInfo, partyVInfo).build(); KTSParameterSpec ktsSpec = new KTSParameterSpec.Builder(symmetricWrappingAlg, keySizeInBits, otherInfo.getEncoded()).withKdfAlgorithm(kemParameters.getKeyDerivationFunction()).build(); keyCipher.init(Cipher.UNWRAP_MODE, privKey, ktsSpec); sKey = keyCipher.unwrap(encryptedKey, helper.getKeyAlgorithmName(encryptedKeyAlgorithm.getAlgorithm()), Cipher.SECRET_KEY); } catch (Exception e) { throw new OperatorException("Unable to unwrap contents key: " + e.getMessage(), e); } return new JceGenericKey(encryptedKeyAlgorithm, sKey); } }
Cipher keyCipher = helper.createAsymmetricWrapper(this.getAlgorithmIdentifier().getAlgorithm(), extraMappings); AlgorithmParameters algParams = helper.createAlgorithmParameters(this.getAlgorithmIdentifier()); sKey = keyCipher.unwrap(encryptedKey, helper.getKeyAlgorithmName(encryptedKeyAlgorithm.getAlgorithm()), Cipher.SECRET_KEY);
public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey) throws OperatorException { try { Cipher keyCipher = helper.createSymmetricWrapper(this.getAlgorithmIdentifier().getAlgorithm()); keyCipher.init(Cipher.UNWRAP_MODE, secretKey); return new JceGenericKey(encryptedKeyAlgorithm, keyCipher.unwrap(encryptedKey, helper.getKeyAlgorithmName(encryptedKeyAlgorithm.getAlgorithm()), Cipher.SECRET_KEY)); } catch (InvalidKeyException e) { throw new OperatorException("key invalid in message.", e); } catch (NoSuchAlgorithmException e) { throw new OperatorException("can't find algorithm.", e); } } }
public byte[] generateWrappedKey(GenericKey encryptionKey) throws OperatorException Cipher keyEncryptionCipher = helper.createAsymmetricWrapper(getAlgorithmIdentifier().getAlgorithm(), extraMappings); AlgorithmParameters algParams = helper.createAlgorithmParameters(this.getAlgorithmIdentifier());
private SignatureOutputStream createSignatureStream(AlgorithmIdentifier algorithm, PublicKey publicKey) throws OperatorCreationException { try { Signature sig = helper.createSignature(algorithm); sig.initVerify(publicKey); return new SignatureOutputStream(sig); } catch (GeneralSecurityException e) { throw new OperatorCreationException("exception on setup: " + e, e); } }
MessageDigest dig = helper.createDigest(algorithm);
public byte[] generateWrappedKey(GenericKey encryptionKey) throws OperatorException { Key contentEncryptionKeySpec = OperatorUtils.getJceKey(encryptionKey); Cipher keyEncryptionCipher = helper.createSymmetricWrapper(this.getAlgorithmIdentifier().getAlgorithm()); try { keyEncryptionCipher.init(Cipher.WRAP_MODE, wrappingKey, random); return keyEncryptionCipher.wrap(contentEncryptionKeySpec); } catch (GeneralSecurityException e) { throw new OperatorException("cannot wrap key: " + e.getMessage(), e); } }
private static String getSignatureName( AlgorithmIdentifier sigAlgId) { ASN1Encodable params = sigAlgId.getParameters(); if (params != null && !DERNull.INSTANCE.equals(params)) { if (sigAlgId.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) { RSASSAPSSparams rsaParams = RSASSAPSSparams.getInstance(params); return getDigestName(rsaParams.getHashAlgorithm().getAlgorithm()) + "WITHRSAANDMGF1"; } } if (oids.containsKey(sigAlgId.getAlgorithm())) { return (String)oids.get(sigAlgId.getAlgorithm()); } return sigAlgId.getAlgorithm().getId(); }
public byte[] generateWrappedKey(GenericKey encryptionKey) throws OperatorException { Cipher keyEncryptionCipher = helper.createAsymmetricWrapper(getAlgorithmIdentifier().getAlgorithm(), new HashMap()); try { DEROtherInfo otherInfo = new DEROtherInfo.Builder(JceSymmetricKeyWrapper.determineKeyEncAlg(symmetricWrappingAlg, keySizeInBits), partyUInfo, partyVInfo).build(); KTSParameterSpec ktsSpec = new KTSParameterSpec.Builder(symmetricWrappingAlg, keySizeInBits, otherInfo.getEncoded()).build(); keyEncryptionCipher.init(Cipher.WRAP_MODE, publicKey, ktsSpec, random); return keyEncryptionCipher.wrap(OperatorUtils.getJceKey(encryptionKey)); } catch (Exception e) { throw new OperatorException("Unable to wrap contents key: " + e.getMessage(), e); } } }
public ContentVerifierProvider build(final X509Certificate certificate) throws OperatorCreationException { final X509CertificateHolder certHolder; try { certHolder = new JcaX509CertificateHolder(certificate); } catch (CertificateEncodingException e) { throw new OperatorCreationException("cannot process certificate: " + e.getMessage(), e); } return new ContentVerifierProvider() { private SignatureOutputStream stream; public boolean hasAssociatedCertificate() { return true; } public X509CertificateHolder getAssociatedCertificate() { return certHolder; } public ContentVerifier get(AlgorithmIdentifier algorithm) throws OperatorCreationException
public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey) throws OperatorException { GenericHybridParameters params = GenericHybridParameters.getInstance(this.getAlgorithmIdentifier().getParameters()); Cipher keyCipher = helper.createAsymmetricWrapper(this.getAlgorithmIdentifier().getAlgorithm(), extraMappings); String symmetricWrappingAlg = helper.getWrappingAlgorithmName(params.getDem().getAlgorithm()); RsaKemParameters kemParameters = RsaKemParameters.getInstance(params.getKem().getParameters()); int keySizeInBits = kemParameters.getKeyLength().intValue() * 8; Key sKey; try { DEROtherInfo otherInfo = new DEROtherInfo.Builder(params.getDem(), partyUInfo, partyVInfo).build(); KTSParameterSpec ktsSpec = new KTSParameterSpec.Builder(symmetricWrappingAlg, keySizeInBits, otherInfo.getEncoded()).withKdfAlgorithm(kemParameters.getKeyDerivationFunction()).build(); keyCipher.init(Cipher.UNWRAP_MODE, privKey, ktsSpec); sKey = keyCipher.unwrap(encryptedKey, helper.getKeyAlgorithmName(encryptedKeyAlgorithm.getAlgorithm()), Cipher.SECRET_KEY); } catch (Exception e) { throw new OperatorException("Unable to unwrap contents key: " + e.getMessage(), e); } return new JceGenericKey(encryptedKeyAlgorithm, sKey); } }
Cipher keyCipher = helper.createAsymmetricWrapper(this.getAlgorithmIdentifier().getAlgorithm(), extraMappings); AlgorithmParameters algParams = helper.createAlgorithmParameters(this.getAlgorithmIdentifier()); sKey = keyCipher.unwrap(encryptedKey, helper.getKeyAlgorithmName(encryptedKeyAlgorithm.getAlgorithm()), Cipher.SECRET_KEY);
public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey) throws OperatorException { try { Cipher keyCipher = helper.createSymmetricWrapper(this.getAlgorithmIdentifier().getAlgorithm()); keyCipher.init(Cipher.UNWRAP_MODE, secretKey); return new JceGenericKey(encryptedKeyAlgorithm, keyCipher.unwrap(encryptedKey, helper.getKeyAlgorithmName(encryptedKeyAlgorithm.getAlgorithm()), Cipher.SECRET_KEY)); } catch (InvalidKeyException e) { throw new OperatorException("key invalid in message.", e); } catch (NoSuchAlgorithmException e) { throw new OperatorException("can't find algorithm.", e); } } }
public byte[] generateWrappedKey(GenericKey encryptionKey) throws OperatorException Cipher keyEncryptionCipher = helper.createAsymmetricWrapper(getAlgorithmIdentifier().getAlgorithm(), extraMappings); AlgorithmParameters algParams = helper.createAlgorithmParameters(this.getAlgorithmIdentifier());
private SignatureOutputStream createSignatureStream(AlgorithmIdentifier algorithm, PublicKey publicKey) throws OperatorCreationException { try { Signature sig = helper.createSignature(algorithm); sig.initVerify(publicKey); return new SignatureOutputStream(sig); } catch (GeneralSecurityException e) { throw new OperatorCreationException("exception on setup: " + e, e); } }
MessageDigest dig = helper.createDigest(algorithm);
public byte[] generateWrappedKey(GenericKey encryptionKey) throws OperatorException { Key contentEncryptionKeySpec = OperatorUtils.getJceKey(encryptionKey); Cipher keyEncryptionCipher = helper.createSymmetricWrapper(this.getAlgorithmIdentifier().getAlgorithm()); try { keyEncryptionCipher.init(Cipher.WRAP_MODE, wrappingKey, random); return keyEncryptionCipher.wrap(contentEncryptionKeySpec); } catch (GeneralSecurityException e) { throw new OperatorException("cannot wrap key: " + e.getMessage(), e); } }