Search in sources :

Example 1 with X509Certificate

use of org.mozilla.jss.crypto.X509Certificate in project OpenAM by OpenRock.

the class SecureLogHelperJSSImpl method signMAC.

/**
     * Signs the given MAC
     * @param mac the mac to be signed
     * @return signed MAC for given mac entry
     * @throws Exception if it fails to sign the MAC
     */
public byte[] signMAC(byte[] mac) throws Exception {
    try {
        PrivateKey loggerPrivKey = null;
        X509Certificate cert = null;
        try {
            cert = cryptoMgr.findCertByNickname(loggerKey);
        } catch (Exception e) {
            Debug.error("SecureLogHelper.signMAC() : " + " Exception : ", e);
        }
        try {
            loggerPrivKey = cryptoMgr.findPrivKeyByCert(cert);
        } catch (Exception e) {
            Debug.error("SecureLogHelper.signMAC() : " + " Exception : ", e);
        }
        Signature loggerSign = Signature.getInstance(signingAlgorithm);
        loggerSign.initSign(loggerPrivKey);
        loggerSign.update(mac);
        byte[] signedBytes = loggerSign.sign();
        writeToSecretStore(signedBytes, logFileName, loggerPass, currentSignature);
        return signedBytes;
    } catch (Exception e) {
        Debug.error("SecureLogHelper.signMAC() : " + " Exception : ", e);
        throw new Exception(e.getMessage());
    }
}
Also used : PrivateKey(java.security.PrivateKey) Signature(java.security.Signature) X509Certificate(org.mozilla.jss.crypto.X509Certificate)

Example 2 with X509Certificate

use of org.mozilla.jss.crypto.X509Certificate in project OpenAM by OpenRock.

the class SecureLogHelperJSSImpl method verifySignature.

/**
     * Verifies the given signature
     * @param signedObject the signature to be verified
     * @param mac mac entry for the signature
     * @return true if signature for mac is valid
     * @throws Exception if it fails to verify signature value for mac entry
     */
public boolean verifySignature(byte[] signedObject, byte[] mac) throws Exception {
    try {
        PublicKey loggerPubKey = null;
        X509Certificate cert = cryptoMgr.findCertByNickname(loggerKey);
        loggerPubKey = cert.getPublicKey();
        Signature verifySign = Signature.getInstance(signingAlgorithm);
        verifySign.initVerify(loggerPubKey);
        verifySign.update(mac);
        return verifySign.verify(signedObject);
    } catch (Exception e) {
        Debug.error("SecureLogHelper.verifySignature() : " + " Exception : ", e);
        throw new Exception(e.getMessage());
    }
}
Also used : PublicKey(java.security.PublicKey) Signature(java.security.Signature) X509Certificate(org.mozilla.jss.crypto.X509Certificate)

Aggregations

Signature (java.security.Signature)2 X509Certificate (org.mozilla.jss.crypto.X509Certificate)2 PrivateKey (java.security.PrivateKey)1 PublicKey (java.security.PublicKey)1