use of com.github.zhenwei.provider.jcajce.io.MacOutputStream in project LinLong-Java by zhenwei1108.
the class JceKEKAuthenticatedRecipient method getRecipientOperator.
public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentMacAlgorithm, byte[] encryptedContentEncryptionKey) throws CMSException {
final Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentMacAlgorithm, encryptedContentEncryptionKey);
final Mac dataMac = contentHelper.createContentMac(secretKey, contentMacAlgorithm);
return new RecipientOperator(new MacCalculator() {
public AlgorithmIdentifier getAlgorithmIdentifier() {
return contentMacAlgorithm;
}
public GenericKey getKey() {
return new JceGenericKey(contentMacAlgorithm, secretKey);
}
public OutputStream getOutputStream() {
return new MacOutputStream(dataMac);
}
public byte[] getMac() {
return dataMac.doFinal();
}
});
}
use of com.github.zhenwei.provider.jcajce.io.MacOutputStream in project LinLong-Java by zhenwei1108.
the class JcePKCS12MacCalculatorBuilder method build.
public MacCalculator build(final char[] password) throws OperatorCreationException {
if (random == null) {
random = new SecureRandom();
}
try {
final Mac mac = helper.createMac(algorithm.getId());
saltLength = mac.getMacLength();
final byte[] salt = new byte[saltLength];
random.nextBytes(salt);
PBEParameterSpec defParams = new PBEParameterSpec(salt, iterationCount);
final SecretKey key = new PKCS12Key(password);
mac.init(key, defParams);
return new MacCalculator() {
public AlgorithmIdentifier getAlgorithmIdentifier() {
return new AlgorithmIdentifier(algorithm, new PKCS12PBEParams(salt, iterationCount));
}
public OutputStream getOutputStream() {
return new MacOutputStream(mac);
}
public byte[] getMac() {
return mac.doFinal();
}
public GenericKey getKey() {
return new GenericKey(getAlgorithmIdentifier(), key.getEncoded());
}
};
} catch (Exception e) {
throw new OperatorCreationException("unable to create MAC calculator: " + e.getMessage(), e);
}
}
use of com.github.zhenwei.provider.jcajce.io.MacOutputStream in project LinLong-Java by zhenwei1108.
the class JcePKCS12MacCalculatorBuilderProvider method get.
public PKCS12MacCalculatorBuilder get(final AlgorithmIdentifier algorithmIdentifier) {
return new PKCS12MacCalculatorBuilder() {
public MacCalculator build(final char[] password) throws OperatorCreationException {
final PKCS12PBEParams pbeParams = PKCS12PBEParams.getInstance(algorithmIdentifier.getParameters());
try {
final ASN1ObjectIdentifier algorithm = algorithmIdentifier.getAlgorithm();
final Mac mac = helper.createMac(algorithm.getId());
PBEParameterSpec defParams = new PBEParameterSpec(pbeParams.getIV(), pbeParams.getIterations().intValue());
final SecretKey key = new PKCS12Key(password);
mac.init(key, defParams);
return new MacCalculator() {
public AlgorithmIdentifier getAlgorithmIdentifier() {
return new AlgorithmIdentifier(algorithm, pbeParams);
}
public OutputStream getOutputStream() {
return new MacOutputStream(mac);
}
public byte[] getMac() {
return mac.doFinal();
}
public GenericKey getKey() {
return new GenericKey(getAlgorithmIdentifier(), key.getEncoded());
}
};
} catch (Exception e) {
throw new OperatorCreationException("unable to create MAC calculator: " + e.getMessage(), e);
}
}
public AlgorithmIdentifier getDigestAlgorithmIdentifier() {
return new AlgorithmIdentifier(algorithmIdentifier.getAlgorithm(), DERNull.INSTANCE);
}
};
}
use of com.github.zhenwei.provider.jcajce.io.MacOutputStream in project LinLong-Java by zhenwei1108.
the class JceKeyTransAuthenticatedRecipient method getRecipientOperator.
public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentMacAlgorithm, byte[] encryptedContentEncryptionKey) throws CMSException {
final Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentMacAlgorithm, encryptedContentEncryptionKey);
final Mac dataMac = contentHelper.createContentMac(secretKey, contentMacAlgorithm);
return new RecipientOperator(new MacCalculator() {
public AlgorithmIdentifier getAlgorithmIdentifier() {
return contentMacAlgorithm;
}
public GenericKey getKey() {
return new JceGenericKey(contentMacAlgorithm, secretKey);
}
public OutputStream getOutputStream() {
return new MacOutputStream(dataMac);
}
public byte[] getMac() {
return dataMac.doFinal();
}
});
}
use of com.github.zhenwei.provider.jcajce.io.MacOutputStream in project LinLong-Java by zhenwei1108.
the class JcePasswordAuthenticatedRecipient method getRecipientOperator.
public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentMacAlgorithm, byte[] derivedKey, byte[] encryptedContentEncryptionKey) throws CMSException {
final Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentMacAlgorithm, derivedKey, encryptedContentEncryptionKey);
final Mac dataMac = helper.createContentMac(secretKey, contentMacAlgorithm);
return new RecipientOperator(new MacCalculator() {
public AlgorithmIdentifier getAlgorithmIdentifier() {
return contentMacAlgorithm;
}
public GenericKey getKey() {
return new JceGenericKey(contentMacAlgorithm, secretKey);
}
public OutputStream getOutputStream() {
return new MacOutputStream(dataMac);
}
public byte[] getMac() {
return dataMac.doFinal();
}
});
}
Aggregations