diff options
author | David Hook <dgh@cryptoworkshop.com> | 2014-07-18 14:33:40 +0400 |
---|---|---|
committer | David Hook <dgh@cryptoworkshop.com> | 2014-07-18 14:33:40 +0400 |
commit | 71135a1ca95c4b5240c7d5b3cc095467b0c4cc57 (patch) | |
tree | a46a676cf2e2ab66b6dfaa69ac4a0800944b6073 | |
parent | ef949f8392e123e4a7d4bec14d8600ea65a3f7e5 (diff) |
BJA-467 added support for passing in a specific locale to help with date interpretation.
-rw-r--r-- | prov/src/main/java/org/bouncycastle/jcajce/spec/SkeinParameterSpec.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/prov/src/main/java/org/bouncycastle/jcajce/spec/SkeinParameterSpec.java b/prov/src/main/java/org/bouncycastle/jcajce/spec/SkeinParameterSpec.java index b43aa959..084f0e88 100644 --- a/prov/src/main/java/org/bouncycastle/jcajce/spec/SkeinParameterSpec.java +++ b/prov/src/main/java/org/bouncycastle/jcajce/spec/SkeinParameterSpec.java @@ -10,6 +10,7 @@ import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.Iterator; +import java.util.Locale; import java.util.Map; import org.bouncycastle.util.Arrays; @@ -248,6 +249,41 @@ public class SkeinParameterSpec } /** + * 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 org.bouncycastle.jcajce.spec.SkeinParameterSpec#PARAM_TYPE_KEY_IDENTIFIER} parameter. */ public Builder setPublicKey(byte[] publicKey) |