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


Java BouncyCastleOpenSSLKey类代码示例

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


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

示例1: testEcryptedToString

import org.globus.gsi.bc.BouncyCastleOpenSSLKey; //导入依赖的package包/类
public void testEcryptedToString() throws Exception {
       KeyPair keyPair = getKeyPair();
OpenSSLKey inKey = new BouncyCastleOpenSSLKey(keyPair.getPrivate());
assertTrue(!inKey.isEncrypted());
inKey.encrypt(pwd);
assertTrue(inKey.isEncrypted());
       
       ByteArrayInputStream in = null;
       in = new ByteArrayInputStream(toString(inKey).getBytes());
       OpenSSLKey outKey = new BouncyCastleOpenSSLKey(in);
       assertTrue(outKey.isEncrypted());

       in = new ByteArrayInputStream(toString(outKey).getBytes());
       OpenSSLKey outKey2 = new BouncyCastleOpenSSLKey(in);
       assertTrue(outKey2.isEncrypted());
   }
 
开发者ID:NCIP,项目名称:cagrid-general,代码行数:17,代码来源:BouncyCastleOpenSSLKeyTest.java

示例2: save

import org.globus.gsi.bc.BouncyCastleOpenSSLKey; //导入依赖的package包/类
/**
    * Saves the credential into a specified output stream.
    * The self-signed certificates in the certificate chain will not be saved.
    * The output stream should always be closed after calling this function.
    *
    * @param out the output stream to write the credential to.
    * @exception IOException if any error occurred during saving.
    */
   public void save(OutputStream out) 
throws IOException {

try {
    CertUtil.writeCertificate(out, this.certs[0]);
    
    OpenSSLKey k = new BouncyCastleOpenSSLKey(key);
    k.writeTo(out);
    
    for (int i=1;i<this.certs.length;i++) {
	// this will skip the self-signed certificates
	if (this.certs[i].getSubjectDN().equals(certs[i].getIssuerDN())) continue;
	CertUtil.writeCertificate(out, this.certs[i]);
    }
} catch (CertificateEncodingException e) {
           throw new ChainedIOException(e.getMessage(), e);
}

out.flush();
   }
 
开发者ID:NCIP,项目名称:cagrid-general,代码行数:29,代码来源:GlobusCredential.java

示例3: writeObject

import org.globus.gsi.bc.BouncyCastleOpenSSLKey; //导入依赖的package包/类
private void writeObject(ObjectOutputStream oos) throws IOException {
    byte [] encoded;

    // write key
    OpenSSLKey encodedKey = new BouncyCastleOpenSSLKey(this.key);
    encoded = encodedKey.getEncoded();
    oos.writeInt(encoded.length);
    oos.write(encoded);

    // write certs
    oos.writeInt(this.certs.length);
    try {
        for (int i=0;i<this.certs.length;i++) {
            encoded = this.certs[i].getEncoded();
            oos.writeInt(encoded.length);
            oos.write(encoded);
        }
    } catch (Exception e) {
        throw new ChainedIOException("", e);
    }
}
 
开发者ID:NCIP,项目名称:cagrid-general,代码行数:22,代码来源:GlobusCredential.java

示例4: testStore

import org.globus.gsi.bc.BouncyCastleOpenSSLKey; //导入依赖的package包/类
public void testStore() throws Exception {
       String credName = "foobar";
       String credDesc = "foobar description";

       StoreParams storeRequest = new StoreParams();
       storeRequest.setUserName(username);
       storeRequest.setCredentialName(credName);
       storeRequest.setCredentialDescription(credDesc);

       GlobusCredential globusCred = 
           ((GlobusGSSCredentialImpl)cred).getGlobusCredential();

myProxy.store(cred,
                     globusCred.getCertificateChain(),
                     new BouncyCastleOpenSSLKey(globusCred.getPrivateKey()),
                     storeRequest);
   }
 
开发者ID:NCIP,项目名称:cagrid-general,代码行数:18,代码来源:MyProxyTest.java

示例5: getPrivateKey

import org.globus.gsi.bc.BouncyCastleOpenSSLKey; //导入依赖的package包/类
/**
 * Decode userkey.pem and return it.
 * 
 * <pre>
 * *** WARNING *** this return the DECRYPTED key. do not store or keep it around in memory.
 * </pre>
 * 
 * @throws Exception
 */
public static PrivateKey getPrivateKey(String filename, Secret passprhase) throws Exception
{
    // X509Certificate userCert =
    // CertUtil.loadCertificate(this.getDefaultUserCertLocation());
    OpenSSLKey key = new BouncyCastleOpenSSLKey(filename);
    // String charSet="UTF-8";

    if (key.isEncrypted())
    {
        try
        {
            // byte[] bytes=passprhase.toByteBuffer("UTF-8").array();
            // key.decrypt(bytes);
            key.decrypt(new String(passprhase.getChars()));
        }
        catch (GeneralSecurityException e)
        {
            throw new Exception("Wrong password or other security error");
        }
    }

    java.security.PrivateKey userKey = key.getPrivateKey();
    return userKey;
}
 
开发者ID:NLeSC,项目名称:vbrowser,代码行数:34,代码来源:GlobusUtil.java

示例6: writePrivateKey

import org.globus.gsi.bc.BouncyCastleOpenSSLKey; //导入依赖的package包/类
public static String writePrivateKey(PrivateKey key, String password)
		throws Exception {
	OpenSSLKey ssl = new BouncyCastleOpenSSLKey(key);
	if (password != null) {
		ssl.encrypt(password);
	}
	StringWriter sw = new StringWriter();
	ssl.writeTo(sw);
	sw.close();
	StringBuffer buf = sw.getBuffer();
	// strip out any windows-specific carriage return chars
	int winNlChar = -1;
	while ((winNlChar = buf.indexOf("\r")) != -1) {
	    buf.deleteCharAt(winNlChar);
	}
	String s = buf.toString();
	return s;
}
 
开发者ID:NCIP,项目名称:cagrid-core,代码行数:19,代码来源:KeyUtil.java

示例7: createAll

import org.globus.gsi.bc.BouncyCastleOpenSSLKey; //导入依赖的package包/类
private X509Certificate createAll(int index) throws GeneralSecurityException, IOException {
    logger.info("Generating CA key pair");
    KeyPair ca = CertUtil.generateKeyPair(CA_CERT_ALGORITHM, CA_CERT_BITS);
    OpenSSLKey caKey = new BouncyCastleOpenSSLKey(ca.getPrivate());
    logger.info("Self-signing CA certificate");
    X509Certificate caCert = genCert(ca.getPrivate(), ca.getPublic(), CA_CERT_DN, CA_CERT_DN, null);
    
    logger.info("Generating user key pair");
    KeyPair user = CertUtil.generateKeyPair(CA_CERT_ALGORITHM, CA_CERT_BITS);
    OpenSSLKey userKey = new BouncyCastleOpenSSLKey(user.getPrivate());
    logger.info("Signing user certificate");
    X509Certificate userCert = genCert(ca.getPrivate(), user.getPublic(), USER_CERT_DN, CA_CERT_DN,
        createExtensions(ca.getPublic(), user.getPublic()));
    logger.info("Generating proxy certificate");
    GlobusCredential proxy = makeProxy(user, userCert);
    
    try {
        logger.info("Writing keys, certificates, and proxy");
        writeKey(caKey, makeFile(CA_KEY_NAME_PREFIX, index));
        writeCert(caCert, makeFile(CA_CRT_NAME_PREFIX, index));
        writeKey(userKey, makeFile(USER_KEY_NAME_PREFIX, index));
        writeCert(userCert, makeFile(USER_CRT_NAME_PREFIX, index));
        writeProxy(proxy, makeFile(PROXY_NAME_PREFIX, index));
        copySigningPolicy(index);
    }
    catch (GeneralSecurityException e) {
        deleteAll(index);
        throw e;
    }
    return cert;
}
 
开发者ID:swift-lang,项目名称:swift-k,代码行数:32,代码来源:AutoCA.java

示例8: createProxy

import org.globus.gsi.bc.BouncyCastleOpenSSLKey; //导入依赖的package包/类
public GlobusCredential createProxy(String pwd)
throws Exception {   

getProperties();

userCert = CertUtil.loadCertificate(props.getUserCertFile());

OpenSSLKey key = 
    new BouncyCastleOpenSSLKey(props.getUserKeyFile());

if (key.isEncrypted()) {
    try {
	key.decrypt(pwd);
    } catch(GeneralSecurityException e) {
	throw new Exception("Wrong password or other security error");
    }
}

PrivateKey userKey = key.getPrivateKey();

BouncyCastleCertProcessingFactory factory =
    BouncyCastleCertProcessingFactory.getDefault();

int proxyType = (getLimited()) ? 
    GSIConstants.DELEGATION_LIMITED :
    GSIConstants.DELEGATION_FULL;

return factory.createCredential(new X509Certificate[] {userCert},
				userKey,
				props.getProxyStrength(), 
				props.getProxyLifeTime() * 3600,
				proxyType,
				(X509ExtensionSet)null);
   }
 
开发者ID:NCIP,项目名称:cagrid-general,代码行数:35,代码来源:DefaultGridProxyModel.java

示例9: testDecryptedToString

import org.globus.gsi.bc.BouncyCastleOpenSSLKey; //导入依赖的package包/类
public void testDecryptedToString() throws Exception {
       KeyPair keyPair = getKeyPair();
OpenSSLKey inKey = new BouncyCastleOpenSSLKey(keyPair.getPrivate());
assertTrue(!inKey.isEncrypted());
       
       ByteArrayInputStream in = null;
       in = new ByteArrayInputStream(toString(inKey).getBytes());
       OpenSSLKey outKey = new BouncyCastleOpenSSLKey(in);
       assertTrue(!outKey.isEncrypted());

       in = new ByteArrayInputStream(toString(outKey).getBytes());
       OpenSSLKey outKey2 = new BouncyCastleOpenSSLKey(in);
       assertTrue(!outKey2.isEncrypted());
   }
 
开发者ID:NCIP,项目名称:cagrid-general,代码行数:15,代码来源:BouncyCastleOpenSSLKeyTest.java

示例10: sign

import org.globus.gsi.bc.BouncyCastleOpenSSLKey; //导入依赖的package包/类
public byte[] sign() throws Exception
{
	try
	{

		ByteArrayOutputStream b = new ByteArrayOutputStream() ;
		new DEROutputStream( b ).writeObject( acinfo ) ;

		Signature sig = Signature.getInstance( signatureAlgorithm.getObjectId().getId() ) ;

		String hostPrivateKeyLocation = new String( System.getProperty( "user.home" ) + "/gridsecurity/hostkey.pem" ) ;

		OpenSSLKey key = new BouncyCastleOpenSSLKey( hostPrivateKeyLocation ) ;

		PrivateKey pk = key.getPrivateKey() ;

		if( pk != null )
		{
			sig.initSign( pk ) ;
			sig.update( b.toByteArray() ) ;
			byte[] sigBytes = sig.sign() ;
			return sigBytes ;
		} 

	}

	catch( Exception e )
	{
		throw e ;
	}

	return new byte[0] ;
}
 
开发者ID:NLeSC,项目名称:vbrowser,代码行数:34,代码来源:VOMSAttributeCertificate.java

示例11: loadPrivateKey

import org.globus.gsi.bc.BouncyCastleOpenSSLKey; //导入依赖的package包/类
public static PrivateKey loadPrivateKey(File location, String password)
		throws IOException, GeneralSecurityException {
	OpenSSLKey key = new BouncyCastleOpenSSLKey(location.getAbsolutePath());
	if (key.isEncrypted()) {
		key.decrypt(password);
	}
	return key.getPrivateKey();
}
 
开发者ID:NCIP,项目名称:cagrid-core,代码行数:9,代码来源:KeyUtil.java

示例12: testEncrypt

import org.globus.gsi.bc.BouncyCastleOpenSSLKey; //导入依赖的package包/类
public void testEncrypt() throws Exception {
       KeyPair keyPair = getKeyPair();

OpenSSLKey key = new BouncyCastleOpenSSLKey(keyPair.getPrivate());

assertTrue(!key.isEncrypted());

key.encrypt(pwd);

assertTrue(key.isEncrypted());
   }
 
开发者ID:NCIP,项目名称:cagrid-general,代码行数:12,代码来源:BouncyCastleOpenSSLKeyTest.java

示例13: testEncryptAES

import org.globus.gsi.bc.BouncyCastleOpenSSLKey; //导入依赖的package包/类
public void testEncryptAES() throws Exception {
       KeyPair keyPair = getKeyPair();

OpenSSLKey key = new BouncyCastleOpenSSLKey(keyPair.getPrivate());

assertTrue(!key.isEncrypted());

       key.setEncryptionAlgorithm("AES-128-CBC");

key.encrypt(pwd);

assertTrue(key.isEncrypted());

       key.writeTo(System.out);
   }
 
开发者ID:NCIP,项目名称:cagrid-general,代码行数:16,代码来源:BouncyCastleOpenSSLKeyTest.java


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