List of usage examples for org.bouncycastle.crypto Digest update
public void update(byte in);
From source file:com.github.capone.protocol.crypto.SymmetricKey.java
License:Open Source License
protected static SymmetricKey fromScalarMultiplication(PrivateKey sk, PublicKey pk, boolean localKeyFirst) throws InvalidKeyException { byte[] scalarmult = new byte[SodiumConstants.SCALAR_BYTES]; Sodium.crypto_scalarmult_curve25519(scalarmult, sk.toBytes(), pk.toBytes()); Digest digest = new Digest(); digest.update(scalarmult); if (localKeyFirst) { digest.update(sk.getPublicKey().toBytes()); digest.update(pk.toBytes());/* ww w . j av a2s. c o m*/ } else { digest.update(pk.toBytes()); digest.update(sk.getPublicKey().toBytes()); } return SymmetricKey.fromBytes(digest.digest()); }
From source file:com.github.horrorho.inflatabledonkey.crypto.rfc6637.RFC6637KDF.java
License:Open Source License
public byte[] apply(ECPoint S, byte[] fingerprint) throws IOException { // RFC Sections 7, 8 byte[] ZB = S.getAffineXCoord().getEncoded(); Digest digest = digestFactory.get(); digest.update((byte) 0x00); // 00 digest.update((byte) 0x00); // 00 digest.update((byte) 0x00); // 00 digest.update((byte) 0x01); // 01 digest.update(ZB, 0, ZB.length); // ZB // Params//from w ww . j a va 2 s . c o m digest.update(formattedOid, 0, formattedOid.length); // curve_OID_len || curve_OID digest.update(publicKeyAlgID); // public_key_alg_ID digest.update((byte) 0x03); // 03 digest.update((byte) 0x01); // 01 digest.update(kdfHashID); // KDF_hash_ID digest.update(symAlgID); // KEK_alg_ID for AESKeyWrap digest.update(ANONYMOUS_SENDER, 0, ANONYMOUS_SENDER.length); // "Anonymous Sender " digest.update(fingerprint, 0, fingerprint.length); // recipient_fingerprint byte[] hash = new byte[digest.getDigestSize()]; digest.doFinal(hash, 0); return hash; }
From source file:com.nokia.xfolite.xforms.xpath.XFormsCoreFunctionLibrary.java
License:Open Source License
public static String digest_function(String s, String method, String encoding) { //#debug info System.out.println("Digest function invoked with params(" + s + "," + method + "," + encoding + ")"); Digest digest = null; Encoder encoder = null;//from ww w. j ava 2s .c o m if (encoding.equals("base64")) { encoder = new Base64Encoder(); } else if (encoding.equals("hex")) { encoder = new HexEncoder(); } if (method.equals("SHA-1")) { digest = new SHA1Digest(); } else if (method.equals("SHA-256")) { digest = new SHA256Digest(); } else if (method.equals("SHA-512")) { digest = new SHA512Digest(); } else if (method.equals("MD5")) { digest = new MD5Digest(); } if (encoder == null) { throw new XPathException(XPathException.TYPE_ERR, "XForms function digest() only supports hex and base64 encoding."); } if (digest == null) { throw new XPathException(XPathException.TYPE_ERR, "XForms function digest() only supports MD5, SHA-1, SHA-256 and SHA-512 digests."); } int len = s.length(); for (int i = 0; i < len; i++) { digest.update((byte) s.charAt(i)); // FIXME: Better not use non-ASCII characters! } byte[] data = new byte[digest.getDigestSize()]; digest.doFinal(data, 0); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); try { encoder.encode(data, 0, data.length, bOut); } catch (IOException e) { throw new XPathException(XPathException.TYPE_ERR, "Exception when encoding digest: " + e); } byte[] out = bOut.toByteArray(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < out.length; i++) { sb.append((char) out[i]); // This works fine, neither hex nor base64 encodings produce } return sb.toString(); }
From source file:org.ourfilesystem.security.SecurityTools.java
License:Open Source License
public static void digestBoolean(Digest d, boolean b) { if (b) {/*from w w w . j av a2 s. co m*/ d.update((byte) 1); } else { d.update((byte) 0); } }
From source file:org.ourfilesystem.security.SecurityTools.java
License:Open Source License
public static void digestDate(Digest d, Date dt) { if (dt == null) { d.update((byte) 2); } else {/* ww w . j ava 2 s . co m*/ d.update((byte) 1); digestLong(d, dt.getTime()); } }
From source file:org.ourfilesystem.security.SecurityTools.java
License:Open Source License
public static void digestPostTemplate(Digest d, PostTemplate p) { if (p == null) { d.update((byte) 2); } else {// ww w . j a va 2 s .c o m for (int c = 0; c < 10; c++) { String s = p.getBool(c); digestString(d, s); } for (int c = 0; c < 10; c++) { String s = p.getDouble(c); digestString(d, s); } for (int c = 0; c < 10; c++) { String s = p.getNum(c); digestString(d, s); } for (int c = 0; c < 3; c++) { String s = p.getRef(c); digestString(d, s); } for (int c = 0; c < 8; c++) { String s = p.getString(c); digestString(d, s); } digestString(d, p.getTemplateName()); digestString(d, p.getTemplateDescription()); } }
From source file:org.ourfilesystem.security.SecurityTools.java
License:Open Source License
public static void digestPostMessage(Digest d, PostMessage m) { if (m == null) { d.update((byte) 2); } else {//from w w w .ja v a2 s . c o m d.update((byte) 1); digestString(d, m.getComment()); digestString(d, m.getString0()); digestString(d, m.getString1()); digestString(d, m.getString2()); digestString(d, m.getString3()); digestString(d, m.getString4()); digestString(d, m.getString5()); digestString(d, m.getString6()); digestString(d, m.getString7()); digestString(d, m.getFileName()); digestString(d, m.getSubject()); digestDouble(d, m.getDouble0()); digestDouble(d, m.getDouble1()); digestDouble(d, m.getDouble2()); digestDouble(d, m.getDouble3()); digestDouble(d, m.getDouble4()); digestDouble(d, m.getDouble5()); digestDouble(d, m.getDouble6()); digestDouble(d, m.getDouble7()); digestDouble(d, m.getDouble8()); digestDouble(d, m.getDouble9()); digestLong(d, m.getNum0()); digestLong(d, m.getNum1()); digestLong(d, m.getNum2()); digestLong(d, m.getNum3()); digestLong(d, m.getNum4()); digestLong(d, m.getNum5()); digestLong(d, m.getNum6()); digestLong(d, m.getNum7()); digestLong(d, m.getNum8()); digestLong(d, m.getNum9()); digestBBytes(d, m.getRef0()); digestBBytes(d, m.getRef1()); digestBBytes(d, m.getRef2()); digestBBytes(d, m.getUseTemplate()); digestBoolean(d, m.isBool0()); digestBoolean(d, m.isBool1()); digestBoolean(d, m.isBool2()); digestBoolean(d, m.isBool3()); digestBoolean(d, m.isBool4()); digestBoolean(d, m.isBool5()); digestBoolean(d, m.isBool6()); digestBoolean(d, m.isBool7()); digestBoolean(d, m.isBool8()); digestBoolean(d, m.isBool9()); } }