@Test public void testDeserialize() throws Exception { byte[] encryptedContent = HexUtils.toBytes("01074b1955bf07aaa979ae8af6eebfea5da8e83cad505edbaade9ba4ed528a8d" + "e36c95ece996189dedf4756fba2599f94b4f370d701366e2f0ba4e59111c0787" + "708cf4b0b82de558b4d8bf5d90b3512f09814d605d4c14f2f85b596211f83918" + "c31c4bef19ea473045022100ddbc9b06625c2b3c9cbfb27b6ac39596bd13daf4" + "3d4ddecbb7257a0d26f5e2c402200a5bd5fd27df7ac262ac3cff9d5398742c6f" + "d9c76c427548667bee45dcb1134c"); byte[] apub = HexUtils.toBytes("028747be6de07552c48f9db23617792d47df1accd611175f6dfe636f4098984a09"); byte[] wrongApub = HexUtils.toBytes("028747be6de07552c48f9db23617792d47df1accd611175f6dfe636f4098984a08"); BackupPayload payload = BackupPayload.deserialize(encryptedContent); assertEquals("content hash", "89bfc7bf81f8e3b2944c4903b68034dc7317806b40f2d225fe4b13907fdb225d", HexUtils.toHex(payload.getHashedContentToSign().getBytes())); assertTrue("signature check", payload.verifySignature(apub)); assertFalse("failing signature check", payload.verifySignature(wrongApub)); }
public static BackupPayload deserialize(byte[] data){ ByteReader reader = new ByteReader(data); try { byte version = reader.get(); int timestamp = reader.getIntLE(); byte[] iv = reader.getBytes(16); int cipherTextLen = (int)reader.getCompactInt(); byte[] cipherText = reader.getBytes(cipherTextLen); int sigLen = (int)reader.getCompactInt(); byte[] signature = reader.getBytes(sigLen); return new BackupPayload(version, timestamp, iv, cipherText, signature); } catch (ByteReader.InsufficientBytesException e) { throw new IllegalArgumentException("Backup payload invalid"); } }
BackupPayload { public static BackupPayload deserialize(byte[] data){ ByteReader reader = new ByteReader(data); try { byte version = reader.get(); int timestamp = reader.getIntLE(); byte[] iv = reader.getBytes(16); int cipherTextLen = (int)reader.getCompactInt(); byte[] cipherText = reader.getBytes(cipherTextLen); int sigLen = (int)reader.getCompactInt(); byte[] signature = reader.getBytes(sigLen); return new BackupPayload(version, timestamp, iv, cipherText, signature); } catch (ByteReader.InsufficientBytesException e) { throw new IllegalArgumentException("Backup payload invalid"); } } }
BackupPayload { public static BackupPayload deserialize(byte[] data){ ByteReader reader = new ByteReader(data); try { byte version = reader.get(); int timestamp = reader.getIntLE(); byte[] iv = reader.getBytes(16); int cipherTextLen = (int)reader.getCompactInt(); byte[] cipherText = reader.getBytes(cipherTextLen); int sigLen = (int)reader.getCompactInt(); byte[] signature = reader.getBytes(sigLen); return new BackupPayload(version, timestamp, iv, cipherText, signature); } catch (ByteReader.InsufficientBytesException e) { throw new IllegalArgumentException("Backup payload invalid"); } } private  BackupPayload(byte version, int timestamp, byte[] iv, byte[] cipherText, byte[] signature);  BackupPayload(byte version, int timestamp, byte[] iv, byte[] cipherText, PrivateKey signatureKey); }
BackupPayload { public static BackupPayload deserialize(byte[] data){ ByteReader reader = new ByteReader(data); try { byte version = reader.get(); int timestamp = reader.getIntLE(); byte[] iv = reader.getBytes(16); int cipherTextLen = (int)reader.getCompactInt(); byte[] cipherText = reader.getBytes(cipherTextLen); int sigLen = (int)reader.getCompactInt(); byte[] signature = reader.getBytes(sigLen); return new BackupPayload(version, timestamp, iv, cipherText, signature); } catch (ByteReader.InsufficientBytesException e) { throw new IllegalArgumentException("Backup payload invalid"); } } private  BackupPayload(byte version, int timestamp, byte[] iv, byte[] cipherText, byte[] signature);  BackupPayload(byte version, int timestamp, byte[] iv, byte[] cipherText, PrivateKey signatureKey); static BackupPayload deserialize(byte[] data); byte[] serialize(); Sha256Hash getHashedContentToSign(); boolean verifySignature(final byte[] apub); byte[] getSignature(); @Override boolean equals(Object o); @Override int hashCode(); }
BackupPayload { public static BackupPayload deserialize(byte[] data){ ByteReader reader = new ByteReader(data); try { byte version = reader.get(); int timestamp = reader.getIntLE(); byte[] iv = reader.getBytes(16); int cipherTextLen = (int)reader.getCompactInt(); byte[] cipherText = reader.getBytes(cipherTextLen); int sigLen = (int)reader.getCompactInt(); byte[] signature = reader.getBytes(sigLen); return new BackupPayload(version, timestamp, iv, cipherText, signature); } catch (ByteReader.InsufficientBytesException e) { throw new IllegalArgumentException("Backup payload invalid"); } } private  BackupPayload(byte version, int timestamp, byte[] iv, byte[] cipherText, byte[] signature);  BackupPayload(byte version, int timestamp, byte[] iv, byte[] cipherText, PrivateKey signatureKey); static BackupPayload deserialize(byte[] data); byte[] serialize(); Sha256Hash getHashedContentToSign(); boolean verifySignature(final byte[] apub); byte[] getSignature(); @Override boolean equals(Object o); @Override int hashCode();  }