if (getDomain() == null)
{
throw new SignatureException("You must have the domain attribute set on your signature header");
}
Signature signature = null;
try
{
signature = Signature.getInstance(algorithm);
signature.initSign(key);
}
catch (Exception e)
{
throw new SignatureException(e);
}
if (this.headers.size() > 0)
{
StringBuffer headerCat = new StringBuffer();
int count = 0;
for (int i = 0; i < this.headers.size(); i++)
{
String name = this.headers.get(i);
if (i > 0) headerCat.append(":");
headerCat.append(name);
}
attributes.put(HEADERS, headerCat.toString());
updateSignatureWithHeader(headers, signature);
}
String encodedBodyHash = calculateEncodedHash(body, hashAlgorithm);
attributes.put(BODY_HASH, encodedBodyHash);
StringBuffer dosetaBuffer = new StringBuffer();
boolean first = true;
for (Map.Entry<String, String> entry : attributes.entrySet())
{
if (first) first = false;
else dosetaBuffer.append(";");
dosetaBuffer.append(entry.getKey()).append("=").append(entry.getValue());
}
if (!first) dosetaBuffer.append(";");
dosetaBuffer.append("b=");
String dosetaHeader = dosetaBuffer.toString();
signature.update(dosetaHeader.getBytes());
byte[] signed = signature.sign();
setSignature(signed);
String base64Signature = Base64.encodeBytes(signed);
dosetaHeader += base64Signature;
// System.out.println("***: " + dosetaHeader);
this.headerValue = dosetaHeader;