public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey) throws OperatorException { try { Cipher keyCipher = helper.createSymmetricWrapper(this.getAlgorithmIdentifier().getAlgorithm()); keyCipher.init(Cipher.UNWRAP_MODE, secretKey); return new JceGenericKey(encryptedKeyAlgorithm, keyCipher.unwrap(encryptedKey, helper.getKeyAlgorithmName(encryptedKeyAlgorithm.getAlgorithm()), Cipher.SECRET_KEY)); } catch (InvalidKeyException e) { throw new OperatorException("key invalid in message.", e); } catch (NoSuchAlgorithmException e) { throw new OperatorException("can't find algorithm.", e); } } }
public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey) throws OperatorException { try { Cipher keyCipher = helper.createSymmetricWrapper(this.getAlgorithmIdentifier().getAlgorithm()); keyCipher.init(Cipher.UNWRAP_MODE, secretKey); return new JceGenericKey(encryptedKeyAlgorithm, keyCipher.unwrap(encryptedKey, helper.getKeyAlgorithmName(encryptedKeyAlgorithm.getAlgorithm()), Cipher.SECRET_KEY)); } catch (InvalidKeyException e) { throw new OperatorException("key invalid in message.", e); } catch (NoSuchAlgorithmException e) { throw new OperatorException("can't find algorithm.", e); } } }
sKey = keyCipher.unwrap(encryptedKey, helper.getKeyAlgorithmName(encryptedKeyAlgorithm.getAlgorithm()), Cipher.SECRET_KEY);
sKey = keyCipher.unwrap(encryptedKey, helper.getKeyAlgorithmName(encryptedKeyAlgorithm.getAlgorithm()), Cipher.SECRET_KEY);
public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey) throws OperatorException { GenericHybridParameters params = GenericHybridParameters.getInstance(this.getAlgorithmIdentifier().getParameters()); Cipher keyCipher = helper.createAsymmetricWrapper(this.getAlgorithmIdentifier().getAlgorithm(), extraMappings); String symmetricWrappingAlg = helper.getWrappingAlgorithmName(params.getDem().getAlgorithm()); RsaKemParameters kemParameters = RsaKemParameters.getInstance(params.getKem().getParameters()); int keySizeInBits = kemParameters.getKeyLength().intValue() * 8; Key sKey; try { DEROtherInfo otherInfo = new DEROtherInfo.Builder(params.getDem(), partyUInfo, partyVInfo).build(); KTSParameterSpec ktsSpec = new KTSParameterSpec.Builder(symmetricWrappingAlg, keySizeInBits, otherInfo.getEncoded()).withKdfAlgorithm(kemParameters.getKeyDerivationFunction()).build(); keyCipher.init(Cipher.UNWRAP_MODE, privKey, ktsSpec); sKey = keyCipher.unwrap(encryptedKey, helper.getKeyAlgorithmName(encryptedKeyAlgorithm.getAlgorithm()), Cipher.SECRET_KEY); } catch (Exception e) { throw new OperatorException("Unable to unwrap contents key: " + e.getMessage(), e); } return new JceGenericKey(encryptedKeyAlgorithm, sKey); } }
public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey) throws OperatorException { GenericHybridParameters params = GenericHybridParameters.getInstance(this.getAlgorithmIdentifier().getParameters()); Cipher keyCipher = helper.createAsymmetricWrapper(this.getAlgorithmIdentifier().getAlgorithm(), extraMappings); String symmetricWrappingAlg = helper.getWrappingAlgorithmName(params.getDem().getAlgorithm()); RsaKemParameters kemParameters = RsaKemParameters.getInstance(params.getKem().getParameters()); int keySizeInBits = kemParameters.getKeyLength().intValue() * 8; Key sKey; try { DEROtherInfo otherInfo = new DEROtherInfo.Builder(params.getDem(), partyUInfo, partyVInfo).build(); KTSParameterSpec ktsSpec = new KTSParameterSpec.Builder(symmetricWrappingAlg, keySizeInBits, otherInfo.getEncoded()).withKdfAlgorithm(kemParameters.getKeyDerivationFunction()).build(); keyCipher.init(Cipher.UNWRAP_MODE, privKey, ktsSpec); sKey = keyCipher.unwrap(encryptedKey, helper.getKeyAlgorithmName(encryptedKeyAlgorithm.getAlgorithm()), Cipher.SECRET_KEY); } catch (Exception e) { throw new OperatorException("Unable to unwrap contents key: " + e.getMessage(), e); } return new JceGenericKey(encryptedKeyAlgorithm, sKey); } }