Top Description Fields Constructors Methods
org.bouncycastle.asn1

public Class ASN1UTCTime

extends ASN1Primitive
Class Inheritance
Known Direct Subclasses
org.bouncycastle.asn1.DERUTCTime
Imports
java.io.IOException, java.text.ParseException, .SimpleDateFormat, java.util.Date, .Locale, .SimpleTimeZone, org.bouncycastle.util.Arrays, .Strings

- * UTC time object. Internal facade of ASN1UTCTime.

This datatype is valid only from 1950-01-01 00:00:00 UTC until 2049-12-31 23:59:59 UTC.


X.690

11: Restrictions on BER employed by both CER and DER

11.8 UTCTime

11.8.1 The encoding shall terminate with "Z", as described in the ITU-T X.680 | ISO/IEC 8824-1 clause on UTCTime.

11.8.2 The seconds element shall always be present.

11.8.3 Midnight (GMT) shall be represented in the form:

"YYMMDD000000Z"
where "YYMMDD" represents the day following the midnight in question.

Field Summary

Modifier and TypeField and Description
pack-priv final byte[]
pack-priv static final ASN1UniversalType

Constructor Summary

AccessConstructor and Description
public
ASN1UTCTime(String
the time string.
time
)

The correct format for this is YYMMDDHHMMSSZ (it used to be that seconds were never encoded.

public
ASN1UTCTime(Date
the Date to build the time from.
time
)

Base constructor from a java.util.date object

public
ASN1UTCTime(Date
a date object representing the time of interest.
time
,
Locale
an appropriate Locale for producing an ASN.1 UTCTime value.
locale
)

Base constructor from a java.util.date and Locale - you may need to use this if the default locale doesn't use a Gregorian calender so that the GeneralizedTime produced is compatible with other ASN.1 implementations.

pack-priv
ASN1UTCTime(byte[] contents)

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
asn1Equals(ASN1Primitive o)

Implements abstract org.bouncycastle.asn1.ASN1Primitive.asn1Equals.

Equality (similarity) comparison for two ASN1Primitive objects.

pack-priv static ASN1UTCTime
createPrimitive(byte[] contents)

pack-priv void
encode(ASN1OutputStream out, boolean withTag)

Implements abstract org.bouncycastle.asn1.ASN1Primitive.encode.

pack-priv final boolean
encodeConstructed()

Implements abstract org.bouncycastle.asn1.ASN1Primitive.encodeConstructed.

Return true if this objected is a CONSTRUCTED one, false otherwise.

pack-priv int
public Date

Returns:

a date in the range of 1950 to 2049.
getAdjustedDate
()

Return the time as an adjusted date in the range of 1950 - 2049.

public String
getAdjustedTime()

Return a time string as an adjusted date with a 4 digit year.

public Date

Returns:

the resulting date
getDate
()

Return the time as a date based on whatever a 2 digit year will return.

public static ASN1UTCTime

Returns:

an ASN1UTCTime instance, or null.
getInstance
(Object
an ASN1UTCTime or an object that can be converted into one.
obj
)

Return an UTC Time from the passed in object.

public static ASN1UTCTime

Returns:

an ASN1UTCTime instance, or null.
getInstance
(ASN1TaggedObject
the tagged object holding the object we want
taggedObject
,
boolean
true if the object is meant to be explicitly tagged false otherwise.
explicit
)

Return an UTC Time from a tagged object.

public String
getTime()

Return the time - always in the form of YYMMDDhhmmssGMT(+hh:mm|-hh:mm).

public int
hashCode()

Implements abstract org.bouncycastle.asn1.ASN1Primitive.hashCode.

Returns a hash code value for this object.

private boolean
isDigit(int pos)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from org.bouncycastle.asn1.ASN1Primitive:
encodeToencodeToequalsequalsequalsfromByteArraytoASN1PrimitivetoDERObjecttoDLObject

Field Detail

contentsback to summary
pack-priv final byte[] contents
TYPEback to summary
pack-priv static final ASN1UniversalType TYPE

Constructor Detail

ASN1UTCTimeback to summary
public ASN1UTCTime(String time)

The correct format for this is YYMMDDHHMMSSZ (it used to be that seconds were never encoded. When you're creating one of these objects from scratch, that's what you want to use, otherwise we'll try to deal with whatever gets read from the input stream... (this is why the input format is different from the getTime() method output).

Parameters
time:String

the time string.

ASN1UTCTimeback to summary
public ASN1UTCTime(Date time)

Base constructor from a java.util.date object

Parameters
time:Date

the Date to build the time from.

ASN1UTCTimeback to summary
public ASN1UTCTime(Date time, Locale locale)

Base constructor from a java.util.date and Locale - you may need to use this if the default locale doesn't use a Gregorian calender so that the GeneralizedTime produced is compatible with other ASN.1 implementations.

Parameters
time:Date

a date object representing the time of interest.

locale:Locale

an appropriate Locale for producing an ASN.1 UTCTime value.

ASN1UTCTimeback to summary
pack-priv ASN1UTCTime(byte[] contents)

Method Detail

asn1Equalsback to summary
pack-priv boolean asn1Equals(ASN1Primitive o)

Implements abstract org.bouncycastle.asn1.ASN1Primitive.asn1Equals.

Doc from org.bouncycastle.asn1.ASN1Primitive.asn1Equals.

Equality (similarity) comparison for two ASN1Primitive objects.

createPrimitiveback to summary
pack-priv static ASN1UTCTime createPrimitive(byte[] contents)
encodeback to summary
pack-priv void encode(ASN1OutputStream out, boolean withTag) throws IOException

Implements abstract org.bouncycastle.asn1.ASN1Primitive.encode.

encodeConstructedback to summary
pack-priv final boolean encodeConstructed()

Implements abstract org.bouncycastle.asn1.ASN1Primitive.encodeConstructed.

Doc from org.bouncycastle.asn1.ASN1Primitive.encodeConstructed.

Return true if this objected is a CONSTRUCTED one, false otherwise.

Returns:boolean

true if CONSTRUCTED bit set on object's tag, false otherwise.

encodedLengthback to summary
pack-priv int encodedLength(boolean withTag)

Implements abstract org.bouncycastle.asn1.ASN1Primitive.encodedLength.

getAdjustedDateback to summary
public Date getAdjustedDate() throws ParseException

Return the time as an adjusted date in the range of 1950 - 2049.

Returns:Date

a date in the range of 1950 to 2049.

Exceptions
ParseException:
if the date string cannot be parsed.
getAdjustedTimeback to summary
public String getAdjustedTime()

Return a time string as an adjusted date with a 4 digit year. This goes in the range of 1950 - 2049.

getDateback to summary
public Date getDate() throws ParseException

Return the time as a date based on whatever a 2 digit year will return. For standardised processing use getAdjustedDate().

Returns:Date

the resulting date

Exceptions
ParseException:
if the date string cannot be parsed.
getInstanceback to summary
public static ASN1UTCTime getInstance(Object obj)

Return an UTC Time from the passed in object.

Parameters
obj:Object

an ASN1UTCTime or an object that can be converted into one.

Returns:ASN1UTCTime

an ASN1UTCTime instance, or null.

Exceptions
IllegalArgumentException:
if the object cannot be converted.
getInstanceback to summary
public static ASN1UTCTime getInstance(ASN1TaggedObject taggedObject, boolean explicit)

Return an UTC Time from a tagged object.

Parameters
taggedObject:ASN1TaggedObject

the tagged object holding the object we want

explicit:boolean

true if the object is meant to be explicitly tagged false otherwise.

Returns:ASN1UTCTime

an ASN1UTCTime instance, or null.

Exceptions
IllegalArgumentException:
if the tagged object cannot be converted.
getTimeback to summary
public String getTime()

Return the time - always in the form of YYMMDDhhmmssGMT(+hh:mm|-hh:mm).

Normally in a certificate we would expect "Z" rather than "GMT", however adding the "GMT" means we can just use:

    dateF = new SimpleDateFormat("yyMMddHHmmssz");
To read in the time and get a date which is compatible with our local time zone.

Note

In some cases, due to the local date processing, this may lead to unexpected results. If you want to stick the normal convention of 1950 to 2049 use the getAdjustedTime() method.

hashCodeback to summary
public int hashCode()

Implements abstract org.bouncycastle.asn1.ASN1Primitive.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

isDigitback to summary
private boolean isDigit(int pos)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object