sun.security.pkcs11.wrapper.PKCS11Exception Java Examples

The following examples show how to use sun.security.pkcs11.wrapper.PKCS11Exception. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PKCS11Digest.java    From julongchain with Apache License 2.0 6 votes vote down vote up
/**
 * 计算摘要方法1
 * @param msg       消息
 * @param opts      基于PKCS11的Factory
 * @return 摘要信息
 * @throws CspException
 */
public byte[] getDigest(byte[] msg, IPKCS11FactoryOpts opts) throws CspException{

    try {
        CK_MECHANISM ckm = new CK_MECHANISM();
        ckm.mechanism = mechanism;
        //opts.getPKCS11().C_DigestInit(opts.getSessionhandle(), ckm);
        byte[] digest = new byte[digestLength];
        int rv = opts.getPKCS11().C_DigestSingle(opts.getSessionhandle(), ckm,
                msg, 0, msg.length, digest, 0, digestLength);
        if (rv == digestLength)
        {
            return digest;
        }
        else{
        	logger.error("[JC_PKCS]: digest methor1 data length error!");
            throw new CspException("[JC_PKCS]: digest methor1 data length error!");
        }

    }catch(PKCS11Exception ex) {
        ex.printStackTrace();
        String err = String.format("[JC_PKCS]:PKCS11Exception ErrCode: 0x%08x", ex.getErrorCode());
        logger.error(err);
        throw new CspException(err, ex.getCause());
    }
}
 
Example #2
Source File: PKCS11Csp.java    From julongchain with Apache License 2.0 6 votes vote down vote up
@Override
public byte[] rng(int len, IRngOpts opts) throws CspException {
    //byte[] none=new SecureRandom().engineGenerateSeed(len);
    //return none;
	try {
 	byte[] random = new byte[len];
 	//PKCS11FactoryOpts.getPKCS11().C_SeedRandom(PKCS11FactoryOpts.getSessionhandle(), arg1);
 	PKCS11FactoryOpts.getPKCS11().C_GenerateRandom(PKCS11FactoryOpts.getSessionhandle(), random);
 	return random;
	} catch(PKCS11Exception ex) {
		ex.printStackTrace();
        String err = String.format("[JC_PKCS]:PKCS11Exception ErrCode: 0x%08x", ex.getErrorCode());
        csplog.setLogMsg(err, csplog.LEVEL_ERROR, PKCS11Csp.class);
        throw new CspException(err, ex.getCause());
	}
	
}
 
Example #3
Source File: PKCS11FactoryOpts.java    From julongchain with Apache License 2.0 5 votes vote down vote up
@Override
public void optFinalized() throws CspException{
    try {
        p11.C_CloseSession(sessionhandle);
    }
    catch (PKCS11Exception ex){
        String err = String.format("[JC_PKCS]:PKCS11Exception code: 0x%08x", ex.getErrorCode());
        csplog.setLogMsg(err, csplog.LEVEL_ERROR, PKCS11FactoryOpts.class);
        throw new CspException(err, ex.getCause());
    }
}
 
Example #4
Source File: PKCS11Digest.java    From julongchain with Apache License 2.0 5 votes vote down vote up
/**
 * 计算摘要方法2
 * @param msg       消息
 * @param opts      基于PKCS11的Factory
 * @return 摘要信息
 * @throws CspException
 */
public static byte[] getDigestwithUpdate(byte[] msg, IPKCS11FactoryOpts opts) throws CspException{

    try {

        CK_MECHANISM ckm = new CK_MECHANISM();
        ckm.mechanism = mechanism;
        opts.getPKCS11().C_DigestInit(opts.getSessionhandle(), ckm);
        byte[] digest = new byte[digestLength];
        opts.getPKCS11().C_DigestUpdate(opts.getSessionhandle(), 0, msg, 0, msg.length);
        int rv = opts.getPKCS11().C_DigestFinal(opts.getSessionhandle(), digest, 0, digestLength);
        if (rv == digestLength)
        {
            return digest;
        }
        else{
        	logger.error("[JC_PKCS]: digest methor2 data length error!");
            throw new CspException("[JC_PKCS]: digest methor2 data length error!");
        }

    }catch(PKCS11Exception ex) {
        ex.printStackTrace();
        String err = String.format("[JC_PKCS]:PKCS11Exception ErrCode: 0x%08x", ex.getErrorCode());
        throw new CspException(err, ex.getCause());
    }

}
 
Example #5
Source File: P11KeyFactory.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPublicKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #6
Source File: P11KeyFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPrivateKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #7
Source File: P11KeyFactory.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPrivateKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #8
Source File: P11KeyFactory.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPublicKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #9
Source File: P11KeyFactory.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPrivateKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #10
Source File: P11KeyFactory.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPublicKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #11
Source File: P11KeyFactory.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPrivateKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #12
Source File: P11KeyFactory.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPublicKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #13
Source File: P11KeyFactory.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPrivateKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #14
Source File: P11KeyFactory.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPublicKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #15
Source File: P11KeyFactory.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPrivateKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #16
Source File: P11KeyFactory.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPublicKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #17
Source File: P11KeyFactory.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPrivateKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #18
Source File: P11KeyFactory.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPrivateKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #19
Source File: P11KeyFactory.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPublicKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #20
Source File: P11KeyFactory.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPublicKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #21
Source File: P11KeyFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPublicKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #22
Source File: P11KeyFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPrivateKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #23
Source File: P11KeyFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPublicKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #24
Source File: P11KeyFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPrivateKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #25
Source File: P11KeyFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPublicKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #26
Source File: P11KeyFactory.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPrivateKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #27
Source File: P11KeyFactory.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPublicKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #28
Source File: P11KeyFactory.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPrivateKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #29
Source File: P11KeyFactory.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPublicKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;
 
Example #30
Source File: P11KeyFactory.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
abstract <T extends KeySpec> T  implGetPrivateKeySpec(P11Key key, Class<T> keySpec,
Session[] session) throws PKCS11Exception, InvalidKeySpecException;