From 71135a1ca95c4b5240c7d5b3cc095467b0c4cc57 Mon Sep 17 00:00:00 2001 From: David Hook Date: Fri, 18 Jul 2014 20:33:40 +1000 Subject: BJA-467 added support for passing in a specific locale to help with date interpretation. --- .../jcajce/spec/SkeinParameterSpec.java | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'prov') 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; @@ -247,6 +248,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. + *

+ * The format is YYYYMMDD email@address distinguisher, 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. */ -- cgit v1.2.3