codec.pkcs12
Class AuthenticatedSafe

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.ArrayList
                    |
                    +--codec.asn1.ASN1AbstractCollection
                          |
                          +--codec.asn1.ASN1Sequence
                                |
                                +--codec.asn1.ASN1SequenceOf
                                      |
                                      +--codec.pkcs12.AuthenticatedSafe
All Implemented Interfaces:
ASN1Collection, ASN1CollectionOf, ASN1Type, Cloneable, Collection, Externalizable, List, Serializable

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,v 1.4 2005/03/22 13:57:42 flautens Exp $"
Author:
Michele Boivin
See Also:
Serialized Form

Field Summary
static int NO_PROTECTION
          identifies no protection mode
static int PASSWORD_PROTECTION
          identifies password protection mode
static 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.
 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, readExternal, setConstraint, setExplicit, setOptional, writeExternal
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, 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, remove, 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, remove, removeAll, retainAll, subList
 

Field Detail

NO_PROTECTION

public static final int NO_PROTECTION
identifies no protection mode

PASSWORD_PROTECTION

public static final int PASSWORD_PROTECTION
identifies password protection mode

PUBLIC_KEY_PROTECTION

public static final 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.

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

AuthenticatedSafe

public AuthenticatedSafe(SafeContents safe,
                         SecretKey key,
                         String algorithm,
                         AlgorithmParameters params,
                         X509Certificate[] cert)
                  throws IOException,
                         ASN1Exception,
                         BadNameException,
                         GeneralSecurityException
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
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

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

addSafeContents

public void addSafeContents(SafeContents safe,
                            SecretKey key,
                            String algorithm,
                            AlgorithmParameters params,
                            X509Certificate[] cert)
                     throws IOException,
                            ASN1Exception,
                            BadNameException,
                            GeneralSecurityException
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

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
Returns:
the protection mode of each SafeContents

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.

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.

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.

toString

public String toString()
Returns a human-readable String representation of this object.
Overrides:
toString in class ASN1AbstractCollection
Returns:
String representation of this object.


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.