List of usage examples for org.bouncycastle.asn1.nist NISTObjectIdentifiers id_aes128_CBC
ASN1ObjectIdentifier id_aes128_CBC
To view the source code for org.bouncycastle.asn1.nist NISTObjectIdentifiers id_aes128_CBC.
Click Source Link
From source file:craterdog.security.RsaCertificateManager.java
License:Open Source License
@Override public String encodePrivateKey(PrivateKey key, char[] password) { logger.entry();/*from ww w.j a va 2 s .c o m*/ try (StringWriter swriter = new StringWriter(); PemWriter pwriter = new PemWriter(swriter)) { OutputEncryptor encryptor = new JcePKCSPBEOutputEncryptorBuilder(NISTObjectIdentifiers.id_aes128_CBC) .setProvider(PROVIDER_NAME).build(password); PKCS8Generator generator = new JcaPKCS8Generator(key, encryptor); pwriter.writeObject(generator); pwriter.flush(); String result = swriter.toString(); logger.exit(); return result; } catch (IOException | OperatorCreationException e) { RuntimeException exception = new RuntimeException( "An unexpected exception occurred while attempting to encode a private key.", e); throw logger.throwing(exception); } }
From source file:org.ccnx.ccn.io.content.WrappedKeyTest.java
License:Open Source License
@Test public void testDecodeInputStream() throws Exception { Log.info(Log.FAC_TEST, "Starting testDecodeInputStream"); // don't use setUpBeforeClass, may not be handling slow initialization well setupTest();//from www .j a v a 2 s . c o m WrappedKey wk = new WrappedKey(wrappingKeyID, dummyWrappedKey); WrappedKey dwk = new WrappedKey(); WrappedKey bdwk = new WrappedKey(); XMLEncodableTester.encodeDecodeTest("WrappedKey(dummy)", wk, dwk, bdwk); WrappedKey wks = WrappedKey.wrapKey(wrappedAESKey, null, aLabel, wrappingAESKey); WrappedKey dwks = new WrappedKey(); WrappedKey bdwks = new WrappedKey(); XMLEncodableTester.encodeDecodeTest("WrappedKey(symmetric, real)", wks, dwks, bdwks); WrappedKey wka = WrappedKey.wrapKey(wrappedAESKey, NISTObjectIdentifiers.id_aes128_CBC.toString(), aLabel, wrappingKeyPair.getPublic()); wka.setWrappingKeyIdentifier(wrappingKeyID); wka.setWrappingKeyName(wrappingKeyName); WrappedKey dwka = new WrappedKey(); WrappedKey bdwka = new WrappedKey(); XMLEncodableTester.encodeDecodeTest("WrappedKey(assymmetric wrap symmetric, with id and name)", wka, dwka, bdwka); Assert.assertArrayEquals(dwka.wrappingKeyIdentifier(), wrappingKeyID); Log.info(Log.FAC_TEST, "Completed testDecodeInputStream"); }
From source file:org.ccnx.ccn.io.content.WrappedKeyTest.java
License:Open Source License
@Test public void testWrappedKeyObject() throws Exception { Log.info(Log.FAC_TEST, "Starting testWrappedKeyObject"); // don't use setUpBeforeClass, may not be handling slow initialization well setupTest();// w w w . ja v a 2 s. c om WrappedKey wks = WrappedKey.wrapKey(wrappedAESKey, null, aLabel, wrappingAESKey); WrappedKey wka = WrappedKey.wrapKey(wrappedAESKey, NISTObjectIdentifiers.id_aes128_CBC.toString(), aLabel, wrappingKeyPair.getPublic()); wka.setWrappingKeyIdentifier(wrappingKeyID); wka.setWrappingKeyName(wrappingKeyName); CCNHandle thandle = CCNHandle.open(); CCNHandle thandle2 = CCNHandle.open(); Flosser flosser = null; try { flosser = new Flosser(); flosser.handleNamespace(storedKeyName); WrappedKeyObject wko = new WrappedKeyObject(storedKeyName, wks, SaveType.RAW, thandle); wko.save(); Assert.assertTrue(VersioningProfile.hasTerminalVersion(wko.getVersionedName())); // should update in another thread WrappedKeyObject wkoread = new WrappedKeyObject(storedKeyName, thandle2); Assert.assertTrue(wkoread.available()); Assert.assertEquals(wkoread.getVersionedName(), wko.getVersionedName()); Assert.assertEquals(wkoread.wrappedKey(), wko.wrappedKey()); // DKS -- bug in interest handling, can't save wkoread and update wko wko.save(wka); Assert.assertTrue( VersioningProfile.isLaterVersionOf(wko.getVersionedName(), wkoread.getVersionedName())); wkoread.update(); Assert.assertEquals(wkoread.getVersionedName(), wko.getVersionedName()); Assert.assertEquals(wkoread.wrappedKey(), wko.wrappedKey()); Assert.assertEquals(wko.wrappedKey(), wka); } finally { if (null != flosser) { Log.info(Log.FAC_TEST, "WrappedKeyTest: Stopping flosser."); flosser.stop(); Log.info(Log.FAC_TEST, "WrappedKeyTest: flosser stopped."); } thandle.close(); thandle2.close(); } Log.info(Log.FAC_TEST, "Completed testWrappedKeyObject"); }
From source file:org.ndnx.ndn.io.content.WrappedKeyTest.java
License:Open Source License
@Test public void testWrappedKeyObject() throws Exception { Log.info(Log.FAC_TEST, "Starting testWrappedKeyObject"); // don't use setUpBeforeClass, may not be handling slow initialization well setupTest();//from www. ja v a2 s . com WrappedKey wks = WrappedKey.wrapKey(wrappedAESKey, null, aLabel, wrappingAESKey); WrappedKey wka = WrappedKey.wrapKey(wrappedAESKey, NISTObjectIdentifiers.id_aes128_CBC.toString(), aLabel, wrappingKeyPair.getPublic()); wka.setWrappingKeyIdentifier(wrappingKeyID); wka.setWrappingKeyName(wrappingKeyName); NDNHandle thandle = NDNHandle.open(); NDNHandle thandle2 = NDNHandle.open(); Flosser flosser = null; try { flosser = new Flosser(); flosser.handleNamespace(storedKeyName); WrappedKeyObject wko = new WrappedKeyObject(storedKeyName, wks, SaveType.RAW, thandle); wko.save(); Assert.assertTrue(VersioningProfile.hasTerminalVersion(wko.getVersionedName())); // should update in another thread WrappedKeyObject wkoread = new WrappedKeyObject(storedKeyName, thandle2); Assert.assertTrue(wkoread.available()); Assert.assertEquals(wkoread.getVersionedName(), wko.getVersionedName()); Assert.assertEquals(wkoread.wrappedKey(), wko.wrappedKey()); // DKS -- bug in interest handling, can't save wkoread and update wko wko.save(wka); Assert.assertTrue( VersioningProfile.isLaterVersionOf(wko.getVersionedName(), wkoread.getVersionedName())); wkoread.update(); Assert.assertEquals(wkoread.getVersionedName(), wko.getVersionedName()); Assert.assertEquals(wkoread.wrappedKey(), wko.wrappedKey()); Assert.assertEquals(wko.wrappedKey(), wka); } finally { if (null != flosser) { Log.info(Log.FAC_TEST, "WrappedKeyTest: Stopping flosser."); flosser.stop(); Log.info(Log.FAC_TEST, "WrappedKeyTest: flosser stopped."); } thandle.close(); thandle2.close(); } Log.info(Log.FAC_TEST, "Completed testWrappedKeyObject"); }
From source file:org.xwiki.crypto.password.internal.pbe.factory.BcPBES2AesCipherFactory.java
License:Open Source License
private int getAESKeySize(ASN1ObjectIdentifier algId) { if (algId.equals(NISTObjectIdentifiers.id_aes128_CBC)) { return 16; } else if (algId.equals(NISTObjectIdentifiers.id_aes192_CBC)) { return 24; } else if (algId.equals(NISTObjectIdentifiers.id_aes256_CBC)) { return 32; }//from w w w . j a v a 2s . com throw new IllegalArgumentException( "Unexpected algorithm identifier used for PBES2 AES encryption scheme: " + algId.toString()); }
From source file:org.xwiki.crypto.password.internal.pbe.factory.BcPBES2AesCipherFactory.java
License:Open Source License
private ASN1ObjectIdentifier getAESAlgoritmIdentifier(int keySize) { switch (keySize) { case 16://from w w w. j a va 2 s .c om return NISTObjectIdentifiers.id_aes128_CBC; case 24: return NISTObjectIdentifiers.id_aes192_CBC; case 32: return NISTObjectIdentifiers.id_aes256_CBC; default: throw new IllegalArgumentException( "Unexpected key size used for PBES2 AES encryption scheme: " + keySize); } }