当前位置: 首页>>代码示例>>Java>>正文


Java RSAKeyFactory类代码示例

本文整理汇总了Java中sun.security.rsa.RSAKeyFactory的典型用法代码示例。如果您正苦于以下问题:Java RSAKeyFactory类的具体用法?Java RSAKeyFactory怎么用?Java RSAKeyFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RSAKeyFactory类属于sun.security.rsa包,在下文中一共展示了RSAKeyFactory类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generatePublic

import sun.security.rsa.RSAKeyFactory; //导入依赖的package包/类
private PublicKey generatePublic(BigInteger n, BigInteger e)
        throws PKCS11Exception, InvalidKeyException {
    RSAKeyFactory.checkKeyLengths(n.bitLength(), e, -1, 64 * 1024);
    CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
        new CK_ATTRIBUTE(CKA_CLASS, CKO_PUBLIC_KEY),
        new CK_ATTRIBUTE(CKA_KEY_TYPE, CKK_RSA),
        new CK_ATTRIBUTE(CKA_MODULUS, n),
        new CK_ATTRIBUTE(CKA_PUBLIC_EXPONENT, e),
    };
    attributes = token.getAttributes
            (O_IMPORT, CKO_PUBLIC_KEY, CKK_RSA, attributes);
    Session session = null;
    try {
        session = token.getObjSession();
        long keyID = token.p11.C_CreateObject(session.id(), attributes);
        return P11Key.publicKey
            (session, keyID, "RSA", n.bitLength(), attributes);
    } finally {
        token.releaseSession(session);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:P11RSAKeyFactory.java

示例2: generatePrivate

import sun.security.rsa.RSAKeyFactory; //导入依赖的package包/类
private PrivateKey generatePrivate(BigInteger n, BigInteger d)
        throws PKCS11Exception, InvalidKeyException {
    RSAKeyFactory.checkKeyLengths(n.bitLength(), null, -1, 64 * 1024);
    CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
        new CK_ATTRIBUTE(CKA_CLASS, CKO_PRIVATE_KEY),
        new CK_ATTRIBUTE(CKA_KEY_TYPE, CKK_RSA),
        new CK_ATTRIBUTE(CKA_MODULUS, n),
        new CK_ATTRIBUTE(CKA_PRIVATE_EXPONENT, d),
    };
    attributes = token.getAttributes
            (O_IMPORT, CKO_PRIVATE_KEY, CKK_RSA, attributes);
    Session session = null;
    try {
        session = token.getObjSession();
        long keyID = token.p11.C_CreateObject(session.id(), attributes);
        return P11Key.privateKey
            (session,  keyID, "RSA", n.bitLength(), attributes);
    } finally {
        token.releaseSession(session);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:P11RSAKeyFactory.java

示例3: engineInitSign

import sun.security.rsa.RSAKeyFactory; //导入依赖的package包/类
protected void engineInitSign(PrivateKey key) throws InvalidKeyException
{
    // This signature accepts only RSAPrivateKey
    if ((key instanceof sun.security.mscapi.RSAPrivateKey) == false) {
        throw new InvalidKeyException("Key type not supported");
    }
    privateKey = (sun.security.mscapi.RSAPrivateKey) key;

    // Check against the local and global values to make sure
    // the sizes are ok.  Round up to nearest byte.
    RSAKeyFactory.checkKeyLengths(((privateKey.length() + 7) & ~7),
        null, RSAKeyPairGenerator.KEY_SIZE_MIN,
        RSAKeyPairGenerator.KEY_SIZE_MAX);

    this.publicKey = null;
    resetDigest();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:RSASignature.java

示例4: engineInitSign

import sun.security.rsa.RSAKeyFactory; //导入依赖的package包/类
protected void engineInitSign(PrivateKey key) throws InvalidKeyException
{
    // This signature accepts only RSAPrivateKey
    if ((key instanceof sun.security.mscapi.RSAPrivateKey) == false) {
        throw new InvalidKeyException("Key type not supported");
    }
    privateKey = (sun.security.mscapi.RSAPrivateKey) key;

    // Check against the local and global values to make sure
    // the sizes are ok.  Round up to nearest byte.
    RSAKeyFactory.checkKeyLengths(((privateKey.bitLength() + 7) & ~7),
        null, RSAKeyPairGenerator.KEY_SIZE_MIN,
        RSAKeyPairGenerator.KEY_SIZE_MAX);

    this.publicKey = null;
    resetDigest();
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:18,代码来源:RSASignature.java

示例5: getSignatureVerifier

import sun.security.rsa.RSAKeyFactory; //导入依赖的package包/类
@Override
public SignatureVerifier getSignatureVerifier() throws Exception {
    String publicKeyEndpointUri = getTokenEndpoint().replace("/token", "/certs");
    HttpEntity<Void> request = new HttpEntity<Void>(new HttpHeaders());
    LinkedHashMap<String, List<Map<String, Object>>> result =
        restTemplate.getForObject(publicKeyEndpointUri, LinkedHashMap.class);
    Map<String, Object> properties = result.get("keys").get(0);
    BigInteger modulus = new BigInteger(1, Base64Utils.decodeFromUrlSafeString((String) properties.get("n")));
    BigInteger publicExponent = new BigInteger(1, Base64Utils.decodeFromString((String) properties.get("e")));
    try {
        PublicKey publicKey =
            KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(modulus, publicExponent));
        RSAPublicKey rsaKey = (RSAPublicKey) RSAKeyFactory.toRSAKey(publicKey);
        return new RsaVerifier(rsaKey);
    } catch (GeneralSecurityException ex) {
        log.error("could not create key verifier", ex);
        throw ex;
    }
}
 
开发者ID:jhipster,项目名称:generator-jhipster,代码行数:20,代码来源:_KeycloakSignatureVerifierClient.java


注:本文中的sun.security.rsa.RSAKeyFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。