public class AuthenticatedSafe extends java.lang.Object implements ASN1Type
An AuthenticatedSafe object represents a PKCS#7 ContentInfo structure whose
content type is either Data
, EncryptedData
, or
EnvelopedData
, depending on whether the supplied PKCS#12
SafeContents
structure has to be ...
The supplied SafeContents
object consists of a sequence of
SafaBags
. A SafeBag
represents one basic building
block of a PFX PDU by collecting one particular piece of information (a key,
a certificate, ...) together with some optional attributes. Currently,
IAIK-JCE supports the three safe bag types keyBag, pkcs-8ShroudedKeyBag,
and certBag.
All AuthenticatedSafe
objects created as instances of this class
are collected to form an AuthenticatedSafes
object, which is DER
encoded to give the content of a ContentInfo object of type
Data
. If password-integrity mode is chosen, the final PFX PDU is
created by computing a SHA-1 HMAC on the contents of this Data
object, but if public-key integrity mode is chosen, the Data
from the previuos step is digitally signed by creating a SignedData
ContentInfo structure:
PFX ::= SEQUENCE { version Version -- V3(3) for this version. authSafes ContentInfo, -- from PKCS #7 v1.5 -- SignedData in public-key integrity mode -- Data in password integrity mode macData MacData OPTIONAL -- present only in password integrity mode }
For more information consult the PKCS#12 Personal Information Exchange Syntax Standard specification.
When creating a new AuthenticatedSafe
object from
a sequence of safe bags (constituting a
SafeContents
structure), you have to specify if the Data shall be
left unencrypted, or if it shall be password-encrypted (remember that
public-key privacy mode is not supported), e.g.:
SafeBag[] safeBags = ...; ... AuthenticatedSafe authenticatedSafe = null; authenticatedSafe = new AuthenticatedSafe(AuthenticatedSafe.UNENCRYPTED, safeBags);
respectively:
SafeBag[] safeBags = ...; ... AuthenticatedSafe authenticatedSafe = null; authenticatedSafe = new AuthenticatedSafe(AuthenticatedSafe.PASSWORD_ENCRYPTED, safeBags);
SafeBag
,
PKCS12
,
ContentInfo
,
Data
,
SignedData
,
EnvelopedData
,
EncryptedData
Modifier and Type | Field and Description |
---|---|
static int |
PASSWORD_ENCRYPTED
AuthenticatedSafe mode: PASSWORD_ENCRYPTED
|
static int |
PUBLIC_KEY_ENCRYPTED
AuthenticatedSafe mode: PUBLIC_KEY_ENCRYPTED (currently not supported)
|
static int |
UNENCRYPTED
AuthenticatedSafe mode: UNENCRYPTED
|
Constructor and Description |
---|
AuthenticatedSafe(ASN1Object obj)
Creates a new
AuthenticatedSafe object from an ASN1Object. |
AuthenticatedSafe(int mode,
SafeBag[] safeBags)
Creates a new AuthenticatedSafe containing the given SafeBags with the
desired mode.
|
AuthenticatedSafe(int mode,
SafeBag[] safeBags,
int blockSize)
Creates a new AuthenticatedSafe containing the given SafeBags with the
desired mode.
|
Modifier and Type | Method and Description |
---|---|
void |
decode(ASN1Object obj)
Decode and inits this
AuthenticatedSafe from an ASN1Object. |
void |
decrypt(char[] password)
Uses the given password for decrypting the password-based encrypted
contents of this
AuthenticatedSafe to recover the safe bags
constituting this AuthenticatedSafe object. |
void |
encrypt(char[] password,
AlgorithmID algorithm)
Password-based encrypts the Data containing the sequence of safe bags
included in this
AuthenticatedSafe , if the
PASSWORD_ENCRYPTED mode has been set when creating this
AuthenticatedSafe object. |
SafeBag[] |
getSafeBags()
Returns the SafeBags this AuthenticatedSafe contains.
|
void |
setBlockSize(int blockSize)
Sets the block size to be used for encoding the inherent Data package.
|
ASN1Object |
toASN1Object()
Returns this
AuthenticatedSafe as ASN1Object. |
java.lang.String |
toString()
Returns a string giving some information about this
AuthenticatedSafe object. |
public static final int UNENCRYPTED
public static final int PASSWORD_ENCRYPTED
public static final int PUBLIC_KEY_ENCRYPTED
public AuthenticatedSafe(int mode, SafeBag[] safeBags) throws PKCSException
Depending on the specified privacy mode either a ContentInfo object of
content type Data
(mode UNENCRYPTED), or of content type
EncryptedData
is created from the supplied safe bags. The
public-key privacy mode (PUBLIC_KEY_ENCRYPTED) currently is not supported.
mode
- the privacy mode (UNENCRYPTED, PASSWORD_ENCRYPTED,
PUBLIC_KEY_ENCRYPTED)safeBags
- the safe contents as an Array of SafeBagsPKCSException
- if the AutenticatedSafe can not be created for some reason
(e.g. some unknown or unsupported mode is requested)public AuthenticatedSafe(int mode, SafeBag[] safeBags, int blockSize) throws PKCSException
Depending on the specified privacy mode either a ContentInfo object of
content type Data
(mode UNENCRYPTED), or of content type
EncryptedData
is created from the supplied safe bags. The
public-key privacy mode (PUBLIC_KEY_ENCRYPTED) currently is not supported.
mode
- the privacy mode (UNENCRYPTED, PASSWORD_ENCRYPTED,
PUBLIC_KEY_ENCRYPTED)safeBags
- the safe contents as an Array of SafeBagsblockSize
- the blockSize to be used for Data encoding (default: 1024 for
indefinite constructed OCTET_STRING encoding; if not positive,
definite primitive encoding will be used)PKCSException
- if the AutenticatedSafe can not be created for some reason
(e.g. some unknown or unsupported mode is requested)public AuthenticatedSafe(ASN1Object obj) throws PKCSParsingException
AuthenticatedSafe
object from an ASN1Object.obj
- a AuthenticatedSafe as ASN1ObjectPKCSParsingException
- if the object could not be parsedpublic void decode(ASN1Object obj) throws CodingException
AuthenticatedSafe
from an ASN1Object.decode
in interface ASN1Type
obj
- an AuthenticatedSafe
as ASN1ObjectCodingException
- if the object could not be parsedpublic ASN1Object toASN1Object() throws CodingException
AuthenticatedSafe
as ASN1Object.toASN1Object
in interface ASN1Type
AuthenticatedSafe
as ASN1ObjectCodingException
- if there occurs an error while creating the ASN1Objectpublic void encrypt(char[] password, AlgorithmID algorithm) throws java.security.NoSuchAlgorithmException, PKCSException
AuthenticatedSafe
, if the
PASSWORD_ENCRYPTED mode has been set when creating this
AuthenticatedSafe
object.
The general proceeding is described in the PKCS#12.
From the safe bags supplied when creating this AuthenticatedSafe
object,
a PKCS#7 ContentInfo object of content type Data
has been constructed, whose DER
encoding is password-based encrypted when calling this method. By default
the PKCS#5 PBES2 scheme PBES2WithHmacSHA256AndAES256
is used for encrypting the data.
If the UNENCRYPTED mode has been set when creating this
AuthenticatedSafe
object, a call to this method would not have any
effect; if the PUBLIC_KEY_ENCRYPTED mode has been set, calling this
method would raise a RuntimeException, since the public-key privacy mode is
not supported.
password
- the password to encrypt the contentsalgorithm
- the PBE algorithm to be used for encryptionjava.security.NoSuchAlgorithmException
- if there is no implementation of the requested algorithmPKCSException
- if the encryption process fails for some reason (e.g. the
privacy mode that has been set when creating this
AuthenticatedSafe
object is not supportedpublic void decrypt(char[] password) throws PKCSException, java.security.NoSuchAlgorithmException
AuthenticatedSafe
to recover the safe bags
constituting this AuthenticatedSafe
object.
Password based decryption only is performed, if the
PASSWORD_ENCRYPTED privacy mode has been set when creating this
AuthenticatedSafe
object. If the UNENCRYPTED mode has
been set, a call to this method would not have any effect; if the
PUBLIC_KEY_ENCRYPTED mode has been set, calling this method would
raise a RuntimeException, since the public-key privacy mode is not
supported.
password
- the password to decrypt the contentsPKCSException
- if there occurs an error while decryptingjava.security.NoSuchAlgorithmException
- if there is no implementation of the encryption algorithmpublic SafeBag[] getSafeBags()
SafeBag
s this AuthenticatedSafe
contains, as array of SafeBag
SafeBag
public void setBlockSize(int blockSize)
blockSize
- the blockSize to be used for Data encoding (default: 1024 for
indefinite constructed OCTET_STRING encoding; if not positive,
definite primitive encoding will be used)public java.lang.String toString()
AuthenticatedSafe
object.toString
in class java.lang.Object