public BitmessageAddress(String address) { try { this.address = address; byte[] bytes = Base58.decode(address.substring(3)); ByteArrayInputStream in = new ByteArrayInputStream(bytes); AccessCounter counter = new AccessCounter(); this.version = varInt(in, counter); this.stream = varInt(in, counter); this.ripe = Bytes.expand(bytes(in, bytes.length - counter.length() - 4), 20); // test checksum byte[] checksum = Security.doubleSha512(bytes, bytes.length - 4); byte[] expectedChecksum = bytes(in, 4); for (int i = 0; i < 4; i++) { if (expectedChecksum[i] != checksum[i]) throw new IllegalArgumentException("Checksum of address failed"); } if (version < 4) { checksum = Security.sha512(Arrays.copyOfRange(bytes, 0, counter.length()), ripe); this.tag = null; this.publicDecryptionKey = Arrays.copyOfRange(checksum, 0, 32); } else { checksum = Security.doubleSha512(Arrays.copyOfRange(bytes, 0, counter.length()), ripe); this.tag = Arrays.copyOfRange(checksum, 32, 64); this.publicDecryptionKey = Arrays.copyOfRange(checksum, 0, 32); } } catch (IOException e) { throw new RuntimeException(e); } }
public BitmessageAddress(String address) { try { this.address = address; byte[] bytes = Base58.decode(address.substring(3)); ByteArrayInputStream in = new ByteArrayInputStream(bytes); AccessCounter counter = new AccessCounter(); this.version = varInt(in, counter); this.stream = varInt(in, counter); this.ripe = Bytes.expand(bytes(in, bytes.length - counter.length() - 4), 20); // test checksum byte[] checksum = cryptography().doubleSha512(bytes, bytes.length - 4); byte[] expectedChecksum = bytes(in, 4); for (int i = 0; i < 4; i++) { if (expectedChecksum[i] != checksum[i]) throw new IllegalArgumentException("Checksum of address failed"); } if (version < 4) { checksum = cryptography().sha512(Arrays.copyOfRange(bytes, 0, counter.length()), ripe); this.tag = null; this.publicDecryptionKey = Arrays.copyOfRange(checksum, 0, 32); } else { checksum = cryptography().doubleSha512(Arrays.copyOfRange(bytes, 0, counter.length()), ripe); this.tag = Arrays.copyOfRange(checksum, 32, 64); this.publicDecryptionKey = Arrays.copyOfRange(checksum, 0, 32); } } catch (IOException e) { throw new ApplicationException(e); } }
public static CustomMessage read(InputStream in, int length) throws IOException { AccessCounter counter = new AccessCounter(); return new CustomMessage(varString(in, counter), bytes(in, length - counter.length())); }
public static ObjectMessage readObject(InputStream in, int length) throws IOException { AccessCounter counter = new AccessCounter(); byte nonce[] = Decode.bytes(in, 8, counter); long expiresTime = Decode.int64(in, counter); long objectType = Decode.uint32(in, counter); long version = Decode.varInt(in, counter); long stream = Decode.varInt(in, counter); byte[] data = Decode.bytes(in, length - counter.length()); ObjectPayload payload; try { ByteArrayInputStream dataStream = new ByteArrayInputStream(data); payload = Factory.getObjectPayload(objectType, version, stream, dataStream, data.length); } catch (IOException e) { LOG.trace("Could not parse object payload - using generic payload instead", e); payload = new GenericPayload(version, stream, data); } return new ObjectMessage.Builder() .nonce(nonce) .expiresTime(expiresTime) .objectType(objectType) .stream(stream) .payload(payload) .build(); }
public static ObjectMessage readObject(InputStream in, int length) throws IOException { AccessCounter counter = new AccessCounter(); byte nonce[] = Decode.bytes(in, 8, counter); long expiresTime = Decode.int64(in, counter); long objectType = Decode.uint32(in, counter); long version = Decode.varInt(in, counter); long stream = Decode.varInt(in, counter); byte[] data = Decode.bytes(in, length - counter.length()); ObjectPayload payload; try { ByteArrayInputStream dataStream = new ByteArrayInputStream(data); payload = Factory.getObjectPayload(objectType, version, stream, dataStream, data.length); } catch (Exception e) { LOG.trace("Could not parse object payload - using generic payload instead", e); payload = new GenericPayload(version, stream, data); } return new ObjectMessage.Builder() .nonce(nonce) .expiresTime(expiresTime) .objectType(objectType) .stream(stream) .payload(payload) .build(); }
public static CryptoBox read(InputStream stream, int length) throws IOException { AccessCounter counter = new AccessCounter(); return new Builder() .IV(Decode.bytes(stream, 16, counter)) .curveType(Decode.uint16(stream, counter)) .X(Decode.shortVarBytes(stream, counter)) .Y(Decode.shortVarBytes(stream, counter)) .encrypted(Decode.bytes(stream, length - counter.length() - 32)) .MAC(Decode.bytes(stream, 32)) .build(); }
public static CryptoBox read(InputStream stream, int length) throws IOException { AccessCounter counter = new AccessCounter(); return new Builder() .IV(Decode.bytes(stream, 16, counter)) .curveType(Decode.uint16(stream, counter)) .X(Decode.shortVarBytes(stream, counter)) .Y(Decode.shortVarBytes(stream, counter)) .encrypted(Decode.bytes(stream, length - counter.length() - 32)) .MAC(Decode.bytes(stream, 32)) .build(); }