diff options
author | David Hook <dgh@cryptoworkshop.com> | 2014-07-17 10:27:21 +0400 |
---|---|---|
committer | David Hook <dgh@cryptoworkshop.com> | 2014-07-17 10:27:21 +0400 |
commit | ef949f8392e123e4a7d4bec14d8600ea65a3f7e5 (patch) | |
tree | c901d94cfbf678bbf459d5299dff54153d315172 /core/src/main/java/org | |
parent | a02b5f52528e2ed6073793975f161f71fe566b82 (diff) |
BJA-467 added support for passing in a specific locale to help with date interpretation.
Diffstat (limited to 'core/src/main/java/org')
-rw-r--r-- | core/src/main/java/org/bouncycastle/crypto/params/SkeinParameters.java | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/core/src/main/java/org/bouncycastle/crypto/params/SkeinParameters.java b/core/src/main/java/org/bouncycastle/crypto/params/SkeinParameters.java index 4e2edd56..326e106c 100644 --- a/core/src/main/java/org/bouncycastle/crypto/params/SkeinParameters.java +++ b/core/src/main/java/org/bouncycastle/crypto/params/SkeinParameters.java @@ -8,6 +8,7 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Enumeration; import java.util.Hashtable; +import java.util.Locale; import org.bouncycastle.crypto.CipherParameters; import org.bouncycastle.crypto.digests.SkeinDigest; @@ -234,7 +235,7 @@ public class SkeinParameters * @param date the date the personalised application of the Skein was defined. * @param emailAddress the email address of the creation of the personalised application. * @param distinguisher an arbitrary personalisation string distinguishing the application. - * @return + * @return the current builder. */ public Builder setPersonalisation(Date date, String emailAddress, String distinguisher) { @@ -258,6 +259,41 @@ public class SkeinParameters } /** + * Implements the recommended personalisation format for Skein defined in Section 4.11 of + * the Skein 1.3 specification. You may need to use this method if the default locale + * doesn't use a Gregorian calender so that the GeneralizedTime produced is compatible implementations. + * <p> + * The format is <code>YYYYMMDD email@address distinguisher</code>, encoded to a byte + * sequence using UTF-8 encoding. + * + * @param date the date the personalised application of the Skein was defined. + * @param dateLocale locale to be used for date interpretation. + * @param emailAddress the email address of the creation of the personalised application. + * @param distinguisher an arbitrary personalisation string distinguishing the application. + * @return the current builder. + */ + public Builder setPersonalisation(Date date, Locale dateLocale, String emailAddress, String distinguisher) + { + try + { + final ByteArrayOutputStream bout = new ByteArrayOutputStream(); + final OutputStreamWriter out = new OutputStreamWriter(bout, "UTF-8"); + final DateFormat format = new SimpleDateFormat("YYYYMMDD", dateLocale); + out.write(format.format(date)); + out.write(" "); + out.write(emailAddress); + out.write(" "); + out.write(distinguisher); + out.close(); + return set(PARAM_TYPE_PERSONALISATION, bout.toByteArray()); + } + catch (IOException e) + { + throw new IllegalStateException("Byte I/O failed: " + e); + } + } + + /** * Sets the {@link SkeinParameters#PARAM_TYPE_KEY_IDENTIFIER} parameter. */ public Builder setPublicKey(byte[] publicKey) |