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


Java RSAPrivateCrtKeySpec类代码示例

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


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

示例1: setSigningKey

import java.security.spec.RSAPrivateCrtKeySpec; //导入依赖的package包/类
public void setSigningKey(String key) throws Exception {
	this.signingKey = key;
	key = key.trim();

	key = key.replace("-----BEGIN RSA PRIVATE KEY-----\n", "")
			.replace("-----END RSA PRIVATE KEY-----", "").trim().replace("\n", "");
	byte[] encoded = Base64Utils.decodeFromString(key);
	DerInputStream derInputStream = new DerInputStream(encoded);
	DerValue[] seq = derInputStream.getSequence(0);

	BigInteger modulus = seq[1].getBigInteger();
	BigInteger publicExp = seq[2].getBigInteger();
	BigInteger privateExp = seq[3].getBigInteger();
	BigInteger prime1 = seq[4].getBigInteger();
	BigInteger prime2 = seq[5].getBigInteger();
	BigInteger exp1 = seq[6].getBigInteger();
	BigInteger exp2 = seq[7].getBigInteger();
	BigInteger crtCoef = seq[8].getBigInteger();

	RSAPrivateCrtKeySpec keySpec = new RSAPrivateCrtKeySpec(modulus, publicExp,
			privateExp, prime1, prime2, exp1, exp2, crtCoef);
	KeyFactory kf = KeyFactory.getInstance("RSA");
	this.signer = new RSASSASigner(kf.generatePrivate(keySpec));
}
 
开发者ID:making,项目名称:spring-boot-actuator-dashboard,代码行数:25,代码来源:JwtTokenConverter.java

示例2: getPrivateKey

import java.security.spec.RSAPrivateCrtKeySpec; //导入依赖的package包/类
static PrivateKey getPrivateKey() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
    byte[] pkcs1Key = DatatypeConverter.parseBase64Binary(PRIVATE_KEY.replaceAll("(-+BEGIN RSA PRIVATE KEY-+\\r?\\n|-+END RSA PRIVATE KEY-+\\r?\\n?)", ""));
    DerInputStream dis = new DerInputStream(pkcs1Key);
    DerValue[] disSequence = dis.getSequence(0);
    BigInteger modulus = disSequence[1].getBigInteger();
    BigInteger publicExp = disSequence[2].getBigInteger();
    BigInteger privateExp = disSequence[3].getBigInteger();
    BigInteger prime1 = disSequence[4].getBigInteger();
    BigInteger prime2 = disSequence[5].getBigInteger();
    BigInteger exp1 = disSequence[6].getBigInteger();
    BigInteger exp2 = disSequence[7].getBigInteger();
    BigInteger crtCoef = disSequence[8].getBigInteger();
    RSAPrivateCrtKeySpec keySpec = new RSAPrivateCrtKeySpec(modulus, publicExp, privateExp, prime1, prime2, exp1, exp2, crtCoef);
    KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    return keyFactory.generatePrivate(keySpec);
}
 
开发者ID:xunkutech,项目名称:jetbrainslicenseserver4j,代码行数:17,代码来源:JetbrainsLicenseServer.java

示例3: createKeyStore

import java.security.spec.RSAPrivateCrtKeySpec; //导入依赖的package包/类
public static KeyStore createKeyStore(InputStream certInputStream, InputStream keyInputStream, String clientKeyAlgo, char[] clientKeyPassphrase) throws IOException, CertificateException, NoSuchAlgorithmException, InvalidKeySpecException, KeyStoreException {
    CertificateFactory certFactory = CertificateFactory.getInstance("X509");
    X509Certificate cert = (X509Certificate) certFactory.generateCertificate(certInputStream);

    byte[] keyBytes = decodePem(keyInputStream);

    PrivateKey privateKey;

    KeyFactory keyFactory = KeyFactory.getInstance(clientKeyAlgo);
    try {
        // First let's try PKCS8
        privateKey = keyFactory.generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
    } catch (InvalidKeySpecException e) {
        // Otherwise try PKCS8
        RSAPrivateCrtKeySpec keySpec = PKCS1Util.decodePKCS1(keyBytes);
        privateKey = keyFactory.generatePrivate(keySpec);
    }

    KeyStore keyStore = KeyStore.getInstance("JKS");
    keyStore.load(null, clientKeyPassphrase);

    String alias = cert.getSubjectX500Principal().getName();
    keyStore.setKeyEntry(alias, privateKey, clientKeyPassphrase, new Certificate[]{cert});

    return keyStore;
}
 
开发者ID:fabric8io,项目名称:mockwebserver,代码行数:27,代码来源:CertUtils.java

示例4: createKeyStore

import java.security.spec.RSAPrivateCrtKeySpec; //导入依赖的package包/类
public static KeyStore createKeyStore(InputStream certInputStream, InputStream keyInputStream, String clientKeyAlgo, char[] clientKeyPassphrase) throws IOException, CertificateException, NoSuchAlgorithmException, InvalidKeySpecException, KeyStoreException {
    CertificateFactory certFactory = CertificateFactory.getInstance("X509");
    X509Certificate cert = (X509Certificate) certFactory.generateCertificate(certInputStream);

    byte[] keyBytes = decodePem(keyInputStream);

    PrivateKey privateKey;

    KeyFactory keyFactory = KeyFactory.getInstance(clientKeyAlgo);
    try {
      // First let's try PKCS8
      privateKey = keyFactory.generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
    } catch (InvalidKeySpecException e) {
      // Otherwise try PKCS8
      RSAPrivateCrtKeySpec keySpec = PKCS1Util.decodePKCS1(keyBytes);
      privateKey = keyFactory.generatePrivate(keySpec);
    }

    KeyStore keyStore = KeyStore.getInstance("JKS");
    keyStore.load(null, clientKeyPassphrase);

    String alias = cert.getSubjectX500Principal().getName();
    keyStore.setKeyEntry(alias, privateKey, clientKeyPassphrase, new Certificate[]{cert});

    return keyStore;
}
 
开发者ID:fabric8io,项目名称:docker-client,代码行数:27,代码来源:CertUtils.java

示例5: engineGeneratePrivate

import java.security.spec.RSAPrivateCrtKeySpec; //导入依赖的package包/类
@Override
protected PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpecException {
    if (keySpec == null) {
        throw new InvalidKeySpecException("keySpec == null");
    }

    if (keySpec instanceof RSAPrivateCrtKeySpec) {
        return new OpenSSLRSAPrivateCrtKey((RSAPrivateCrtKeySpec) keySpec);
    } else if (keySpec instanceof RSAPrivateKeySpec) {
        return new OpenSSLRSAPrivateKey((RSAPrivateKeySpec) keySpec);
    } else if (keySpec instanceof PKCS8EncodedKeySpec) {
        return OpenSSLKey.getPrivateKey((PKCS8EncodedKeySpec) keySpec,
                NativeConstants.EVP_PKEY_RSA);
    }
    throw new InvalidKeySpecException("Must use RSAPublicKeySpec or PKCS8EncodedKeySpec; was "
            + keySpec.getClass().getName());
}
 
开发者ID:google,项目名称:conscrypt,代码行数:18,代码来源:OpenSSLRSAKeyFactory.java

示例6: generateKeyPair

import java.security.spec.RSAPrivateCrtKeySpec; //导入依赖的package包/类
@Override
public void generateKeyPair() throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException {
	// https://github.com/bcgit/bc-java/blob/53d17ef99e30c6bd49e6eec9235e3eefca6a222d/pkix/src/test/java/org/bouncycastle/cert/test/CertTest.java
	RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(new BigInteger(
			"b4a7e46170574f16a97082b22be58b6a2a629798419be12872a4bdba626cfae9900f76abfb12139dce5de56564fab2b6543165a040c606887420e33d91ed7ed7", 16), new BigInteger("11", 16));
	RSAPrivateCrtKeySpec privKeySpec = new RSAPrivateCrtKeySpec(new BigInteger(
			"b4a7e46170574f16a97082b22be58b6a2a629798419be12872a4bdba626cfae9900f76abfb12139dce5de56564fab2b6543165a040c606887420e33d91ed7ed7", 16), new BigInteger("11", 16), new BigInteger(
			"9f66f6b05410cd503b2709e88115d55daced94d1a34d4e32bf824d0dde6028ae79c5f07b580f5dce240d7111f7ddb130a7945cd7d957d1920994da389f490c89", 16), new BigInteger(
			"c0a0758cdf14256f78d4708c86becdead1b50ad4ad6c5c703e2168fbf37884cb", 16), new BigInteger("f01734d7960ea60070f1b06f2bb81bfac48ff192ae18451d5e56c734a5aab8a5", 16), new BigInteger(
			"b54bb9edff22051d9ee60f9351a48591b6500a319429c069a3e335a1d6171391", 16), new BigInteger("d3d83daf2a0cecd3367ae6f8ae1aeb82e9ac2f816c6fc483533d8297dd7884cd", 16), new BigInteger(
			"b8f52fc6f38593dabb661d3f50f8897f8106eee68b1bce78a95b132b4e5b5d19", 16));

	KeyFactory fact = KeyFactory.getInstance("RSA", "BC");
	setPrivateKey(fact.generatePrivate(privKeySpec));
	setPublicKey(fact.generatePublic(pubKeySpec));
}
 
开发者ID:SAMLRaider,项目名称:SAMLRaider,代码行数:17,代码来源:FakeBurpCertificateBuilder.java

示例7: toJcaKey

import java.security.spec.RSAPrivateCrtKeySpec; //导入依赖的package包/类
@Override
public Key toJcaKey() throws GeneralSecurityException {

    final BigInteger modulus = Encoding.base64urlDecodeUint(n);
    final BigInteger publicExponent = Encoding.base64urlDecodeUint(e);
    if (getUse() == KeyUse.sig || d == null) {
        return KeyFactory.getInstance("RSA")
                .generatePublic(new RSAPublicKeySpec(modulus, publicExponent));
    } else {

        final BigInteger privateExponent = Encoding.base64urlDecodeUint(d);
        final BigInteger primeP = Encoding.base64urlDecodeUint(p);
        final BigInteger primeQ = Encoding.base64urlDecodeUint(q);
        final BigInteger primeExponentP = Encoding.base64urlDecodeUint(dp);
        final BigInteger primeExponentQ = Encoding.base64urlDecodeUint(dq);
        final BigInteger crtCoefficent = Encoding.base64urlDecodeUint(qi);
        return KeyFactory.getInstance("RSA")
                .generatePrivate(new RSAPrivateCrtKeySpec(modulus, publicExponent, privateExponent, primeP, primeQ, primeExponentP, primeExponentQ, crtCoefficent));
    }

}
 
开发者ID:trajano,项目名称:openid-connect,代码行数:22,代码来源:RsaWebKey.java

示例8: toJcaPrivateKey

import java.security.spec.RSAPrivateCrtKeySpec; //导入依赖的package包/类
private static RSAPrivateKey toJcaPrivateKey(
        org.bouncycastle.asn1.pkcs.RSAPrivateKey rsaPrivateKey)
        throws GeneralSecurityException {
    RSAPrivateCrtKeySpec spec = new RSAPrivateCrtKeySpec(rsaPrivateKey.getModulus(),
                                                         rsaPrivateKey.getPublicExponent(),
                                                         rsaPrivateKey.getPrivateExponent(),
                                                         rsaPrivateKey.getPrime1(),
                                                         rsaPrivateKey.getPrime2(),
                                                         rsaPrivateKey.getExponent1(),
                                                         rsaPrivateKey.getExponent2(),
                                                         rsaPrivateKey.getCoefficient());
    KeyFactory kf = KeyFactory.getInstance("RSA", "BC");
    RSAPrivateKey privateKey = (RSAPrivateKey) kf.generatePrivate(spec);

    return privateKey;
}
 
开发者ID:nelenkov,项目名称:keystore-decryptor,代码行数:17,代码来源:SoftKeymasterBlob.java

示例9: testRSAPrivateCrtKeySpec01

import java.security.spec.RSAPrivateCrtKeySpec; //导入依赖的package包/类
/**
 * Test #1 for <code>RSAPrivateCrtKeySpec</code> constructor
 * Assertion: Constructs <code>RSAPrivateCrtKeySpec</code>
 * object using valid parameters
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "Verifies constructor with valid parameters.",
    method = "RSAPrivateCrtKeySpec",
    args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class}
)
public final void testRSAPrivateCrtKeySpec01() {
    KeySpec ks = new RSAPrivateCrtKeySpec(
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE);
    assertTrue(ks instanceof RSAPrivateCrtKeySpec);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:24,代码来源:RSAPrivateCrtKeySpecTest.java

示例10: testRSAPrivateCrtKeySpec02

import java.security.spec.RSAPrivateCrtKeySpec; //导入依赖的package包/类
/**
 * Test #2 for <code>RSAPrivateCrtKeySpec</code> constructor
 * Assertion: Constructs <code>RSAPrivateCrtKeySpec</code>
 * object using valid parameters
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "Verifies constructor with valid parameters.",
    method = "RSAPrivateCrtKeySpec",
    args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class}
)
public final void testRSAPrivateCrtKeySpec02() {
    KeySpec ks = new RSAPrivateCrtKeySpec(
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE);
    assertTrue(ks instanceof RSAPrivateKeySpec);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:24,代码来源:RSAPrivateCrtKeySpecTest.java

示例11: testRSAPrivateCrtKeySpec03

import java.security.spec.RSAPrivateCrtKeySpec; //导入依赖的package包/类
/**
 * Test #3 for <code>RSAPrivateCrtKeySpec</code> constructor
 * Assertion: Constructs <code>RSAPrivateCrtKeySpec</code>
 * object using valid parameters
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "Verifies null as parameters.",
    method = "RSAPrivateCrtKeySpec",
    args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class}
)
public final void testRSAPrivateCrtKeySpec03() {
    new RSAPrivateCrtKeySpec(
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:23,代码来源:RSAPrivateCrtKeySpecTest.java

示例12: testGetCrtCoefficient

import java.security.spec.RSAPrivateCrtKeySpec; //导入依赖的package包/类
/**
 * Test for <code>getCrtCoefficient()</code> method<br>
 * Assertion: returns crt coefficient
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getCrtCoefficient",
    args = {}
)
public final void testGetCrtCoefficient() {
    RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec(
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.valueOf(5L));
    assertTrue(BigInteger.valueOf(5L).equals(ks.getCrtCoefficient()));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:23,代码来源:RSAPrivateCrtKeySpecTest.java

示例13: testGetPrimeExponentP

import java.security.spec.RSAPrivateCrtKeySpec; //导入依赖的package包/类
/**
 * Test for <code>getPrimeExponentP()</code> method<br>
 * Assertion: returns prime exponent P
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getPrimeExponentP",
    args = {}
)
public final void testGetPrimeExponentP() {
    RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec(
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.valueOf(5L),
            BigInteger.ONE,
            BigInteger.ONE);
    assertTrue(BigInteger.valueOf(5L).equals(ks.getPrimeExponentP()));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:23,代码来源:RSAPrivateCrtKeySpecTest.java

示例14: testGetPrimeExponentQ

import java.security.spec.RSAPrivateCrtKeySpec; //导入依赖的package包/类
/**
 * Test for <code>getPrimeExponentQ()</code> method<br>
 * Assertion: returns prime exponent Q
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getPrimeExponentQ",
    args = {}
)
public final void testGetPrimeExponentQ() {
    RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec(
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.valueOf(5L),
            BigInteger.ONE);
    assertTrue(BigInteger.valueOf(5L).equals(ks.getPrimeExponentQ()));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:23,代码来源:RSAPrivateCrtKeySpecTest.java

示例15: testGetPrimeP

import java.security.spec.RSAPrivateCrtKeySpec; //导入依赖的package包/类
/**
 * Test for <code>getPrimeP()</code> method<br>
 * Assertion: returns prime P
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getPrimeP",
    args = {}
)
public final void testGetPrimeP() {
    RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec(
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.valueOf(5L),
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE,
            BigInteger.ONE);
    assertTrue(BigInteger.valueOf(5L).equals(ks.getPrimeP()));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:23,代码来源:RSAPrivateCrtKeySpecTest.java


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