@Override public String serialize(Job job) throws IOException { String plaintext = delegate.serialize(job); if (job.getEncryptionKeys() != null) { MasterSecret masterSecret = ParcelUtil.deserialize(job.getEncryptionKeys().getEncoded(), MasterSecret.CREATOR); MasterCipher masterCipher = new MasterCipher(masterSecret); return masterCipher.encryptBody(plaintext); } else { return plaintext; } }
@Override public Job deserialize(EncryptionKeys keys, boolean encrypted, String serialized) throws IOException { try { String plaintext; if (encrypted) { MasterSecret masterSecret = ParcelUtil.deserialize(keys.getEncoded(), MasterSecret.CREATOR); MasterCipher masterCipher = new MasterCipher(masterSecret); plaintext = masterCipher.decryptBody(serialized); } else { plaintext = serialized; } return delegate.deserialize(keys, encrypted, plaintext); } catch (InvalidMessageException e) { throw new IOException(e); } }