public String sign()

in main/src/main/java/org/apache/james/jdkim/DKIMSigner.java [98:132]


    public String sign(Headers message, BodyHasher bh) throws PermFailException {
        if (!(bh instanceof BodyHasherImpl)) {
            throw new PermFailException(
                    "Supplied BodyHasher has not been generated with this signer");
        }
        BodyHasherImpl bhj = (BodyHasherImpl) bh;
        byte[] computedHash = bhj.getDigest();

        bhj.getSignatureRecord().setBodyHash(computedHash);

        List<CharSequence> headers = bhj.getSignatureRecord().getHeaders();
        try {
            // TODO handle b= in SignatureRecord.
            // whenever any tag is changed the b should be invalidated and the
            // text representation lost.
            // whenever the b value is regenerated it should also be associated
            // with the right test representation.
            // we need a method to "regenerate the text representation" and to
            // retrieve it when it is valid.
            byte[] signatureHash = signatureSign(message, bhj
                    .getSignatureRecord(), privateKey, headers);

            bhj.getSignatureRecord().setSignature(signatureHash);

            return "DKIM-Signature:" + bhj.getSignatureRecord().toString();
        } catch (InvalidKeyException e) {
            throw new PermFailException("Invalid key: " + e.getMessage(), bhj.getSignatureRecord(), e);
        } catch (NoSuchAlgorithmException e) {
            throw new PermFailException("Unknown algorythm: " + e.getMessage(), bhj.getSignatureRecord(),
                    e);
        } catch (SignatureException e) {
            throw new PermFailException("Signing exception: " + e.getMessage(), bhj.getSignatureRecord(),
                    e);
        }
    }