codec.pkcs12
Class AuthenticatedSafe

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList
              extended by codec.asn1.ASN1AbstractCollection
                  extended by codec.asn1.ASN1Sequence
                      extended by codec.asn1.ASN1SequenceOf
                          extended by codec.pkcs12.AuthenticatedSafe
All Implemented Interfaces:
ASN1Collection, ASN1CollectionOf, ASN1Type, Serializable, Cloneable, Iterable, Collection, List, RandomAccess

public class AuthenticatedSafe
extends ASN1SequenceOf
implements Serializable

This class represents an AuthenticatedSafe as defined in PKCS#12. The ASN.1 definition of this structure is

  AuthenticatedSafe ::= SEQUENCE OF ContentInfo
   --Data if unencrypted
   --Encrypted data if password-encrypted
   --Enveloped data if public-key-encrypted
 

PFX The AuthenicatedSafe PDUs hold the data to be transmitted.

Version:
"$Id: AuthenticatedSafe.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Michele Boivin
See Also:
Serialized Form

Field Summary
 int NO_PROTECTION
          identifies no protection mode
private static int[] oid_
          The OID of this structure.
 int PASSWORD_PROTECTION
          identifies password protection mode
 int PUBLIC_KEY_PROTECTION
          identifies public-key-protection mode
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
AuthenticatedSafe()
          the default constructor.
AuthenticatedSafe(SafeContents safe)
          Constructs a SafeContents from a SafeBag.
AuthenticatedSafe(SafeContents safe, char[] passwd, String algorithm)
          Constructs an AuthenticatedSafe and places a SafeContents in it protected by a password.
AuthenticatedSafe(SafeContents safe, SecretKey key, String algorithm, AlgorithmParameters params, X509Certificate[] cert)
          Creates an authenticated safe and places a SafeContents in public-key-encrypted mode inside.
 
Method Summary
 void addSafeContents(SafeContents safe)
          Adds a SafeContents to the AuthenticatedSafe.
 void addSafeContents(SafeContents safe, char[] passwd, String algorithm)
          adds a safeContents to the AuthenticatedSafe and protects it with a password.
 void addSafeContents(SafeContents safe, SecretKey key, String algorithm, AlgorithmParameters params, X509Certificate[] cert)
          Adds a SafeContents to the AuthenticatedSafe.
 ASN1ObjectIdentifier getOID()
          A SafeContents can be put recursively into a SafeBag.
 int[] getProtectionMode()
          Returns the protection mode of each SafeContents in the AuthenticatedSafe
 SafeContents getSafeContents(int i)
          returns the contents of the SafeBag in the AuthenticatedSafe at position i, if the SafeBag is not protected.
 SafeContents getSafeContents(int i, char[] passwd)
          returns the contents of the SafeBag in the AuthenticatedSafe at position i, if the SafeBag is password-protected.
 SafeContents getSafeContents(int i, PrivateKey key, X509Certificate cert)
          returns the contents of the SafeBag in the AuthenticatedSafe at position i, if the SafeBag is public-key-protected.
private  ContentInfo makeData(SafeContents safe)
          returns a ContentInfo with contentType Data to feed to an AuthenticatedSafe.
private  ContentInfo makeEncryptedData(SafeContents safe, char[] pwd, String algorithm)
           
private  ContentInfo makeEnvelopedData(SafeContents safe, SecretKey key, String algorithm, AlgorithmParameters params, X509Certificate[] cert)
           
 String toString()
          Returns a human-readable String representation of this object.
 
Methods inherited from class codec.asn1.ASN1SequenceOf
decode, getElementType, newElement
 
Methods inherited from class codec.asn1.ASN1Sequence
getTag
 
Methods inherited from class codec.asn1.ASN1AbstractCollection
checkConstraints, encode, getCollection, getConstraint, getTagClass, getValue, isExplicit, isOptional, isType, setConstraint, setExplicit, setOptional
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface codec.asn1.ASN1Collection
getCollection
 
Methods inherited from interface codec.asn1.ASN1Type
checkConstraints, encode, getConstraint, getTag, getTagClass, getValue, isExplicit, isOptional, isType, setConstraint, setExplicit, setOptional
 
Methods inherited from interface java.util.Collection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Field Detail

oid_

private static final int[] oid_
The OID of this structure.


NO_PROTECTION

public int NO_PROTECTION
identifies no protection mode


PASSWORD_PROTECTION

public int PASSWORD_PROTECTION
identifies password protection mode


PUBLIC_KEY_PROTECTION

public int PUBLIC_KEY_PROTECTION
identifies public-key-protection mode

Constructor Detail

AuthenticatedSafe

public AuthenticatedSafe()
the default constructor.


AuthenticatedSafe

public AuthenticatedSafe(SafeContents safe)
                  throws IOException,
                         ASN1Exception
Constructs a SafeContents from a SafeBag. WARNING! This SafeContents is not protected.

Parameters:
safe - The SafeContents to put in the AuthenticatedSafe.
Throws:
IOException
ASN1Exception

AuthenticatedSafe

public AuthenticatedSafe(SafeContents safe,
                         char[] passwd,
                         String algorithm)
                  throws IOException,
                         ASN1Exception,
                         GeneralSecurityException
Constructs an AuthenticatedSafe and places a SafeContents in it protected by a password.

Parameters:
safe - The SafeContents to put in the AuthenticatedSafe
passwd - The password used to protect the contents of the SafeContents.
algorithm - the PBE algorithm to be used
Throws:
IOException
ASN1Exception
GeneralSecurityException

AuthenticatedSafe

public AuthenticatedSafe(SafeContents safe,
                         SecretKey key,
                         String algorithm,
                         AlgorithmParameters params,
                         X509Certificate[] cert)
                  throws IOException,
                         ASN1Exception,
                         BadNameException,
                         GeneralSecurityException,
                         CorruptedCodeException
Creates an authenticated safe and places a SafeContents in public-key-encrypted mode inside. The SafeContents will be saved as type EnvelopedData and therefore requires a secret key and a certificate.

Parameters:
safe - The SafeContents to put in the AuthenticatedSafe
key - The secret key for the symmetric encryption
algorithm - the symmetric encryption algorithm
params - algorithm parameters for the symmetric encryption algorithm
cert - The certificate chain for the intended recipients of the SafeContents
Throws:
IOException
ASN1Exception
BadNameException
GeneralSecurityException
CorruptedCodeException
Method Detail

addSafeContents

public void addSafeContents(SafeContents safe)
                     throws IOException,
                            ASN1Exception
Adds a SafeContents to the AuthenticatedSafe. WARNING! This SafeContents is not protected.

Parameters:
safe - the SafeContents to be added to the AuthenticatedSafe
Throws:
IOException
ASN1Exception

addSafeContents

public void addSafeContents(SafeContents safe,
                            char[] passwd,
                            String algorithm)
                     throws IOException,
                            ASN1Exception,
                            GeneralSecurityException
adds a safeContents to the AuthenticatedSafe and protects it with a password.

Parameters:
safe - The SafeContents to put in the AuthenticatedSafe
passwd - The password used to protect the contents of the SafeContents.
algorithm - the PBE algorithm to be used
Throws:
IOException
ASN1Exception
GeneralSecurityException

addSafeContents

public void addSafeContents(SafeContents safe,
                            SecretKey key,
                            String algorithm,
                            AlgorithmParameters params,
                            X509Certificate[] cert)
                     throws IOException,
                            ASN1Exception,
                            BadNameException,
                            GeneralSecurityException,
                            CorruptedCodeException
Adds a SafeContents to the AuthenticatedSafe. The SafeContents will be saved as type EnvelopedData and therefore requires a secret key and a certificate.

Parameters:
safe - The SafeContents to put in the AuthenticatedSafe
key - The secret key for the symmetric encryption
algorithm - the symmetric encryption algorithm
params - algorithm parameters for the symmetric encryption algorithm
cert - The certificate chain for the intended recipients of the SafeContents
Throws:
IOException
ASN1Exception
BadNameException
GeneralSecurityException
CorruptedCodeException

getOID

public ASN1ObjectIdentifier getOID()
A SafeContents can be put recursively into a SafeBag.

Returns:
the OID defining this structure as a SafeContents bag.

getProtectionMode

public int[] getProtectionMode()
Returns the protection mode of each SafeContents in the AuthenticatedSafe


getSafeContents

public SafeContents getSafeContents(int i)
                             throws IOException,
                                    ASN1Exception
returns the contents of the SafeBag in the AuthenticatedSafe at position i, if the SafeBag is not protected.

Parameters:
i - The integer specifying the position.
Returns:
The SafeBag at position i.
Throws:
IOException
ASN1Exception

getSafeContents

public SafeContents getSafeContents(int i,
                                    char[] passwd)
                             throws IOException,
                                    ASN1Exception,
                                    GeneralSecurityException
returns the contents of the SafeBag in the AuthenticatedSafe at position i, if the SafeBag is password-protected.

Parameters:
i - The integer specifying the position.
Returns:
The SafeBag at position i.
Throws:
IOException
ASN1Exception
GeneralSecurityException

getSafeContents

public SafeContents getSafeContents(int i,
                                    PrivateKey key,
                                    X509Certificate cert)
                             throws IOException,
                                    ASN1Exception,
                                    GeneralSecurityException,
                                    NoSuchElementException
returns the contents of the SafeBag in the AuthenticatedSafe at position i, if the SafeBag is public-key-protected.

Parameters:
i - The integer specifying the position.
key - the private key for decrypting the content
cert - the certificate corresponding to the private key
Returns:
The SafeBag at position i.
Throws:
IOException
ASN1Exception
GeneralSecurityException
NoSuchElementException

makeData

private ContentInfo makeData(SafeContents safe)
                      throws IOException,
                             ASN1Exception
returns a ContentInfo with contentType Data to feed to an AuthenticatedSafe.

Returns:
Contentinfo with contentType Data.
Throws:
IOException
ASN1Exception

makeEncryptedData

private ContentInfo makeEncryptedData(SafeContents safe,
                                      char[] pwd,
                                      String algorithm)
                               throws IOException,
                                      ASN1Exception,
                                      GeneralSecurityException
Throws:
IOException
ASN1Exception
GeneralSecurityException

makeEnvelopedData

private ContentInfo makeEnvelopedData(SafeContents safe,
                                      SecretKey key,
                                      String algorithm,
                                      AlgorithmParameters params,
                                      X509Certificate[] cert)
                               throws IOException,
                                      GeneralSecurityException,
                                      BadNameException,
                                      ASN1Exception,
                                      CorruptedCodeException
Throws:
IOException
GeneralSecurityException
BadNameException
ASN1Exception
CorruptedCodeException

toString

public String toString()
Returns a human-readable String representation of this object.

Overrides:
toString in class ASN1AbstractCollection
Returns:
The string representation of this ASN.1 collection.


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.