public static EncryptedPrivateKeyInfo getInstance( Object obj) { if (obj instanceof EncryptedPrivateKeyInfo) { return (EncryptedPrivateKeyInfo)obj; } else if (obj != null) { return new EncryptedPrivateKeyInfo(ASN1Sequence.getInstance(obj)); } return null; }
public PrivateKeyInfo decryptPrivateKeyInfo(InputDecryptorProvider inputDecryptorProvider) throws PKCSException { try { InputDecryptor decrytor = inputDecryptorProvider.get(encryptedPrivateKeyInfo.getEncryptionAlgorithm()); ByteArrayInputStream encIn = new ByteArrayInputStream(encryptedPrivateKeyInfo.getEncryptedData()); return PrivateKeyInfo.getInstance(Streams.readAll(decrytor.getInputStream(encIn))); } catch (Exception e) { throw new PKCSException("unable to read encrypted data: " + e.getMessage(), e); } } }
private static EncryptedPrivateKeyInfo parseBytes(byte[] pkcs8Encoding) throws IOException { try { return EncryptedPrivateKeyInfo.getInstance(ASN1Primitive.fromByteArray(pkcs8Encoding)); } catch (ClassCastException e) { throw new PKCSIOException("malformed data: " + e.getMessage(), e); } catch (IllegalArgumentException e) { throw new PKCSIOException("malformed data: " + e.getMessage(), e); } }
EncryptedPrivateKeyInfo encInfo = EncryptedPrivateKeyInfo.getInstance(encPrivData.getEncryptedPrivateKeyInfo()); PrivateKeyInfo pInfo = PrivateKeyInfo.getInstance(decryptData("PRIVATE_KEY_ENCRYPTION", encInfo.getEncryptionAlgorithm(), password, encInfo.getEncryptedData()));
private PemObject generate(PrivateKeyInfo key, OutputEncryptor encryptor) throws PemGenerationException { try { byte[] keyData = key.getEncoded(); if (encryptor == null) { return new PemObject("PRIVATE KEY", keyData); } ByteArrayOutputStream bOut = new ByteArrayOutputStream(); OutputStream cOut = encryptor.getOutputStream(bOut); cOut.write(key.getEncoded()); cOut.close(); EncryptedPrivateKeyInfo info = new EncryptedPrivateKeyInfo(encryptor.getAlgorithmIdentifier(), bOut.toByteArray()); return new PemObject("ENCRYPTED PRIVATE KEY", info.getEncoded()); } catch (IOException e) { throw new PemGenerationException("unable to process encoded key data: " + e.getMessage(), e); } } }
byte[] kBytes = wrapKey(keyAlgorithm.getId(), privKey, kParams, password); AlgorithmIdentifier kAlgId = new AlgorithmIdentifier(keyAlgorithm, kParams.toASN1Primitive()); org.spongycastle.asn1.pkcs.EncryptedPrivateKeyInfo kInfo = new org.spongycastle.asn1.pkcs.EncryptedPrivateKeyInfo(kAlgId, kBytes); boolean attrSet = false; ASN1EncodableVector kName = new ASN1EncodableVector(); SafeBag kBag = new SafeBag(pkcs8ShroudedKeyBag, kInfo.toASN1Primitive(), new DERSet(kName)); keyS.add(kBag);
public byte[] getEncoded() throws IOException { return encryptedPrivateKeyInfo.getEncoded(); }
if (b.getBagId().equals(pkcs8ShroudedKeyBag)) org.spongycastle.asn1.pkcs.EncryptedPrivateKeyInfo eIn = org.spongycastle.asn1.pkcs.EncryptedPrivateKeyInfo.getInstance(b.getBagValue()); PrivateKey privKey = unwrapKey(eIn.getEncryptionAlgorithm(), eIn.getEncryptedData(), password, wrongPKCS12Zero); org.spongycastle.asn1.pkcs.EncryptedPrivateKeyInfo eIn = org.spongycastle.asn1.pkcs.EncryptedPrivateKeyInfo.getInstance(b.getBagValue()); PrivateKey privKey = unwrapKey(eIn.getEncryptionAlgorithm(), eIn.getEncryptedData(), password, wrongPKCS12Zero);
private PemObject generate(PrivateKeyInfo key, OutputEncryptor encryptor) throws PemGenerationException { try { byte[] keyData = key.getEncoded(); if (encryptor == null) { return new PemObject("PRIVATE KEY", keyData); } ByteArrayOutputStream bOut = new ByteArrayOutputStream(); OutputStream cOut = encryptor.getOutputStream(bOut); cOut.write(key.getEncoded()); cOut.close(); EncryptedPrivateKeyInfo info = new EncryptedPrivateKeyInfo(encryptor.getAlgorithmIdentifier(), bOut.toByteArray()); return new PemObject("ENCRYPTED PRIVATE KEY", info.getEncoded()); } catch (IOException e) { throw new PemGenerationException("unable to process encoded key data: " + e.getMessage(), e); } } }
byte[] kBytes = wrapKey(keyAlgorithm.getId(), privKey, kParams, password); AlgorithmIdentifier kAlgId = new AlgorithmIdentifier(keyAlgorithm, kParams.toASN1Primitive()); org.spongycastle.asn1.pkcs.EncryptedPrivateKeyInfo kInfo = new org.spongycastle.asn1.pkcs.EncryptedPrivateKeyInfo(kAlgId, kBytes); boolean attrSet = false; ASN1EncodableVector kName = new ASN1EncodableVector(); SafeBag kBag = new SafeBag(pkcs8ShroudedKeyBag, kInfo.toASN1Primitive(), new DERSet(kName)); keyS.add(kBag);
public byte[] getEncoded() throws IOException { return encryptedPrivateKeyInfo.getEncoded(); }
if (b.getBagId().equals(pkcs8ShroudedKeyBag)) org.spongycastle.asn1.pkcs.EncryptedPrivateKeyInfo eIn = org.spongycastle.asn1.pkcs.EncryptedPrivateKeyInfo.getInstance(b.getBagValue()); PrivateKey privKey = unwrapKey(eIn.getEncryptionAlgorithm(), eIn.getEncryptedData(), password, wrongPKCS12Zero); org.spongycastle.asn1.pkcs.EncryptedPrivateKeyInfo eIn = org.spongycastle.asn1.pkcs.EncryptedPrivateKeyInfo.getInstance(b.getBagValue()); PrivateKey privKey = unwrapKey(eIn.getEncryptionAlgorithm(), eIn.getEncryptedData(), password, wrongPKCS12Zero);
public PrivateKeyInfo decryptPrivateKeyInfo(InputDecryptorProvider inputDecryptorProvider) throws PKCSException { try { InputDecryptor decrytor = inputDecryptorProvider.get(encryptedPrivateKeyInfo.getEncryptionAlgorithm()); ByteArrayInputStream encIn = new ByteArrayInputStream(encryptedPrivateKeyInfo.getEncryptedData()); return PrivateKeyInfo.getInstance(Streams.readAll(decrytor.getInputStream(encIn))); } catch (Exception e) { throw new PKCSException("unable to read encrypted data: " + e.getMessage(), e); } } }
private static EncryptedPrivateKeyInfo parseBytes(byte[] pkcs8Encoding) throws IOException { try { return EncryptedPrivateKeyInfo.getInstance(ASN1Primitive.fromByteArray(pkcs8Encoding)); } catch (ClassCastException e) { throw new CertIOException("malformed data: " + e.getMessage(), e); } catch (IllegalArgumentException e) { throw new CertIOException("malformed data: " + e.getMessage(), e); } }
public static EncryptedPrivateKeyInfo getInstance( Object obj) { if (obj instanceof EncryptedData) { return (EncryptedPrivateKeyInfo)obj; } else if (obj != null) { return new EncryptedPrivateKeyInfo(ASN1Sequence.getInstance(obj)); } return null; }
AlgorithmIdentifier id = info.getEncryptionAlgorithm(); byte[] iv = ((ASN1OctetString) id.getParameters()).getOctets(); Cipher dec = Cipher.getInstance("AES/CBC/PKCS5Padding"); dec.init(Cipher.UNWRAP_MODE, secret, new IvParameterSpec(iv)); return (PrivateKey) dec.unwrap(info.getEncryptedData(), "RSA", Cipher.PRIVATE_KEY);
/** * Reads in an EncryptedPrivateKeyInfo * * @return the X509Certificate * @throws java.io.IOException if an I/O error occured */ public Object parseObject(PemObject obj) throws IOException { try { return new PKCS8EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfo.getInstance(obj.getContent())); } catch (Exception e) { throw new PEMException("problem parsing ENCRYPTED PRIVATE KEY: " + e.toString(), e); } } }
public PKCS8EncryptedPrivateKeyInfo build( OutputEncryptor encryptor) { try { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); OutputStream cOut = encryptor.getOutputStream(bOut); cOut.write(privateKeyInfo.getEncoded()); cOut.close(); return new PKCS8EncryptedPrivateKeyInfo(new EncryptedPrivateKeyInfo(encryptor.getAlgorithmIdentifier(), bOut.toByteArray())); } catch (IOException e) { throw new IllegalStateException("cannot encode privateKeyInfo"); } } }
/** * Reads in an EncryptedPrivateKeyInfo * * @return the X509Certificate * @throws java.io.IOException if an I/O error occured */ public Object parseObject(PemObject obj) throws IOException { try { return new PKCS8EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfo.getInstance(obj.getContent())); } catch (Exception e) { throw new PEMException("problem parsing ENCRYPTED PRIVATE KEY: " + e.toString(), e); } } }
public PKCS8EncryptedPrivateKeyInfo build( OutputEncryptor encryptor) { try { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); OutputStream cOut = encryptor.getOutputStream(bOut); cOut.write(privateKeyInfo.getEncoded()); cOut.close(); return new PKCS8EncryptedPrivateKeyInfo(new EncryptedPrivateKeyInfo(encryptor.getAlgorithmIdentifier(), bOut.toByteArray())); } catch (IOException e) { throw new IllegalStateException("cannot encode privateKeyInfo"); } } }