
org.testifyproject.bouncycastle.cert.crmf.EncryptedValueParser Maven / Gradle / Ivy
package org.testifyproject.bouncycastle.cert.crmf;
import java.org.testifyproject.testifyproject.ByteArrayInputStream;
import java.org.testifyproject.testifyproject.IOException;
import java.org.testifyproject.testifyproject.InputStream;
import org.testifyproject.bouncycastle.asn1.crmf.EncryptedValue;
import org.testifyproject.bouncycastle.asn1.x509.Certificate;
import org.testifyproject.bouncycastle.cert.X509CertificateHolder;
import org.testifyproject.bouncycastle.operator.InputDecryptor;
import org.testifyproject.bouncycastle.util.Strings;
import org.testifyproject.bouncycastle.util.org.testifyproject.testifyproject.Streams;
/**
* Parser for EncryptedValue structures.
*/
public class EncryptedValueParser
{
private EncryptedValue value;
private EncryptedValuePadder padder;
/**
* Basic constructor - create a parser to read the passed in value.
*
* @param value the value to be parsed.
*/
public EncryptedValueParser(EncryptedValue value)
{
this.value = value;
}
/**
* Create a parser to read the passed in value, assuming the padder was
* applied to the data prior to encryption.
*
* @param value the value to be parsed.
* @param padder the padder to be used to remove padding from the org.testifyproject.testifyprojectcrypted value..
*/
public EncryptedValueParser(EncryptedValue value, EncryptedValuePadder padder)
{
this.value = value;
this.padder = padder;
}
private byte[] org.testifyproject.testifyprojectcryptValue(ValueDecryptorGenerator org.testifyproject.testifyprojectcGen)
throws CRMFException
{
if (value.getIntendedAlg() != null)
{
throw new UnsupportedOperationException();
}
if (value.getValueHint() != null)
{
throw new UnsupportedOperationException();
}
InputDecryptor org.testifyproject.testifyprojectcryptor = org.testifyproject.testifyprojectcGen.getValueDecryptor(value.getKeyAlg(),
value.getSymmAlg(), value.getEncSymmKey().getBytes());
InputStream dataIn = org.testifyproject.testifyprojectcryptor.getInputStream(new ByteArrayInputStream(
value.getEncValue().getBytes()));
try
{
byte[] data = Streams.readAll(dataIn);
if (padder != null)
{
return padder.getUnpaddedData(data);
}
return data;
}
catch (IOException e)
{
throw new CRMFException("Cannot parse org.testifyproject.testifyprojectcrypted data: " + e.getMessage(), e);
}
}
/**
* Read a X.509 certificate.
*
* @param org.testifyproject.testifyprojectcGen the org.testifyproject.testifyprojectcryptor generator to org.testifyproject.testifyprojectcrypt the encrypted value.
* @return an X509CertificateHolder containing the certificate read.
* @throws CRMFException if the org.testifyproject.testifyprojectcrypted data cannot be parsed, or a org.testifyproject.testifyprojectcryptor cannot be generated.
*/
public X509CertificateHolder readCertificateHolder(ValueDecryptorGenerator org.testifyproject.testifyprojectcGen)
throws CRMFException
{
return new X509CertificateHolder(Certificate.getInstance(org.testifyproject.testifyprojectcryptValue(org.testifyproject.testifyprojectcGen)));
}
/**
* Read a pass phrase.
*
* @param org.testifyproject.testifyprojectcGen the org.testifyproject.testifyprojectcryptor generator to org.testifyproject.testifyprojectcrypt the encrypted value.
* @return a pass phrase as recovered from the encrypted value.
* @throws CRMFException if the org.testifyproject.testifyprojectcrypted data cannot be parsed, or a org.testifyproject.testifyprojectcryptor cannot be generated.
*/
public char[] readPassphrase(ValueDecryptorGenerator org.testifyproject.testifyprojectcGen)
throws CRMFException
{
return Strings.fromUTF8ByteArray(org.testifyproject.testifyprojectcryptValue(org.testifyproject.testifyprojectcGen)).toCharArray();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy