public void decrypt(PrivateKey key) throws IOException, DecryptionFailedException { if (payload instanceof Encrypted) { ((Encrypted) payload).decrypt(key.getPrivateEncryptionKey()); } }
public static BitmessageAddress generatePrivateAddress(boolean shorter, long stream, Pubkey.Feature... features) { return new BitmessageAddress(new PrivateKey(shorter, stream, 1000, 1000, features)); }
public BitmessageAddress(String address, String passphrase) { this(address); this.privateKey = new PrivateKey(this, passphrase); this.pubkey = this.privateKey.getPubkey(); if (!Arrays.equals(ripe, privateKey.getPubkey().getRipe())) { throw new IllegalArgumentException("Wrong address or passphrase"); } }
public WifExporter addIdentity(BitmessageAddress identity) { Profile.Section section = ini.add(identity.getAddress()); section.add("label", identity.getAlias()); section.add("enabled", true); section.add("decoy", false); if (identity.isChan()) { section.add("chan", identity.isChan()); } section.add("noncetrialsperbyte", identity.getPubkey().getNonceTrialsPerByte()); section.add("payloadlengthextrabytes", identity.getPubkey().getExtraBytes()); section.add("privsigningkey", exportSecret(identity.getPrivateKey().getPrivateSigningKey())); section.add("privencryptionkey", exportSecret(identity.getPrivateKey().getPrivateEncryptionKey())); return this; }
/** * Calculate the signature of data, using the given private key. * * @param data to be signed * @param privateKey to be used for signing * @return the signature */ public static byte[] getSignature(byte[] data, ch.dissem.bitmessage.entity.valueobject.PrivateKey privateKey) { try { ECParameterSpec spec = new ECParameterSpec( EC_CURVE_PARAMETERS.getCurve(), EC_CURVE_PARAMETERS.getG(), EC_CURVE_PARAMETERS.getN(), EC_CURVE_PARAMETERS.getH(), EC_CURVE_PARAMETERS.getSeed() ); BigInteger d = keyToBigInt(privateKey.getPrivateSigningKey()); KeySpec keySpec = new ECPrivateKeySpec(d, spec); PrivateKey privKey = KeyFactory.getInstance("ECDSA", "BC").generatePrivate(keySpec); Signature sig = Signature.getInstance("ECDSA", "BC"); sig.initSign(privKey); sig.update(data); return sig.sign(); } catch (Exception e) { throw new RuntimeException(e); } }
public BitmessageAddress(PrivateKey privateKey) { this(privateKey.getPubkey()); this.privateKey = privateKey; }
public static List<BitmessageAddress> deterministic(String passphrase, int numberOfAddresses, long version, long stream, boolean shorter) { List<BitmessageAddress> result = new ArrayList<>(numberOfAddresses); List<PrivateKey> privateKeys = PrivateKey.deterministic(passphrase, numberOfAddresses, version, stream, shorter); for (PrivateKey pk : privateKeys) { result.add(new BitmessageAddress(pk)); } return result; }
PrivateKey privateKey = PrivateKey.read(privateKeyStream); address = new BitmessageAddress(privateKey);
@Override public byte[] getSignature(byte[] data, PrivateKey privateKey) { try { ECParameterSpec spec = new ECParameterSpec( EC_CURVE_PARAMETERS.getCurve(), EC_CURVE_PARAMETERS.getG(), EC_CURVE_PARAMETERS.getN(), EC_CURVE_PARAMETERS.getH(), EC_CURVE_PARAMETERS.getSeed() ); BigInteger d = keyToBigInt(privateKey.getPrivateSigningKey()); KeySpec keySpec = new ECPrivateKeySpec(d, spec); java.security.PrivateKey privKey = KeyFactory.getInstance(ALGORITHM_ECDSA, provider) .generatePrivate(keySpec); Signature sig = Signature.getInstance(ALGORITHM_ECDSA, provider); sig.initSign(privKey); sig.update(data); return sig.sign(); } catch (GeneralSecurityException e) { throw new ApplicationException(e); } }
public BitmessageAddress(PrivateKey privateKey) { this(privateKey.getPubkey()); this.privateKey = privateKey; }
public static BitmessageAddress generatePrivateAddress(boolean shorter, long stream, Pubkey.Feature... features) { return new BitmessageAddress(new PrivateKey(shorter, stream, 1000, 1000, features)); }
public void decrypt(PrivateKey key) throws IOException, DecryptionFailedException { if (payload instanceof Encrypted) { ((Encrypted) payload).decrypt(key.getPrivateEncryptionKey()); } }
public static BitmessageAddress chan(long stream, String passphrase) { PrivateKey privateKey = new PrivateKey(Pubkey.LATEST_VERSION, stream, passphrase); BitmessageAddress result = new BitmessageAddress(privateKey); result.chan = true; return result; }
protected void receive(ObjectMessage object, Msg msg) throws IOException { for (BitmessageAddress identity : ctx.getAddressRepository().getIdentities()) { try { msg.decrypt(identity.getPrivateKey().getPrivateEncryptionKey()); Plaintext plaintext = msg.getPlaintext(); plaintext.setTo(identity); if (!object.isSignatureValid(plaintext.getFrom().getPubkey())) { LOG.warn("Msg with IV " + object.getInventoryVector() + " was successfully decrypted, but signature check failed. Ignoring."); } else { receive(object.getInventoryVector(), plaintext); } break; } catch (DecryptionFailedException ignore) { } } }
public static List<PrivateKey> deterministic(String passphrase, int numberOfAddresses, long version, long stream, boolean shorter) { List<PrivateKey> result = new ArrayList<>(numberOfAddresses); Builder builder = new Builder(version, stream, shorter).seed(passphrase); for (int i = 0; i < numberOfAddresses; i++) { builder.generate(); result.add(new PrivateKey(builder)); } return result; }
protected void receive(ObjectMessage object, Msg msg) throws IOException { for (BitmessageAddress identity : ctx.getAddressRepo().getIdentities()) { try { msg.decrypt(identity.getPrivateKey().getPrivateEncryptionKey()); msg.getPlaintext().setTo(identity); if (!object.isSignatureValid(msg.getPlaintext().getFrom().getPubkey())) { LOG.warn("Msg with IV " + object.getInventoryVector() + " was successfully decrypted, but signature check failed. Ignoring."); } else { msg.getPlaintext().setStatus(RECEIVED); msg.getPlaintext().addLabels(ctx.getMessageRepository().getLabels(Label.Type.INBOX, Label.Type.UNREAD)); msg.getPlaintext().setInventoryVector(object.getInventoryVector()); ctx.getMessageRepository().save(msg.getPlaintext()); listener.receive(msg.getPlaintext()); } break; } catch (DecryptionFailedException ignore) { } } }
public BitmessageAddress createIdentity(boolean shorter, Feature... features) { final BitmessageAddress identity = new BitmessageAddress(new PrivateKey( shorter, ctx.getStreams()[0], NETWORK_NONCE_TRIALS_PER_BYTE, NETWORK_EXTRA_BYTES, features )); ctx.getAddressRepository().save(identity); if (sendPubkeyOnIdentityCreation) { ctx.sendPubkey(identity, identity.getStream()); } return identity; }
public BitmessageAddress createIdentity(boolean shorter, Feature... features) { BitmessageAddress identity = new BitmessageAddress(new PrivateKey( shorter, ctx.getStreams()[0], ctx.getNetworkNonceTrialsPerByte(), ctx.getNetworkExtraBytes(), features )); ctx.getAddressRepo().save(identity); // TODO: this should happen in a separate thread ctx.sendPubkey(identity, identity.getStream()); return identity; }
public static BitmessageAddress createIdentityFromPrivateKey(String address, byte[] privateSigningKey, byte[] privateEncryptionKey, long nonceTrialsPerByte, long extraBytes, int behaviourBitfield) { BitmessageAddress temp = new BitmessageAddress(address); PrivateKey privateKey = new PrivateKey(privateSigningKey, privateEncryptionKey, createPubkey(temp.getVersion(), temp.getStream(), Security.createPublicKey(privateSigningKey).getEncoded(false), Security.createPublicKey(privateEncryptionKey).getEncoded(false), nonceTrialsPerByte, extraBytes, behaviourBitfield)); BitmessageAddress result = new BitmessageAddress(privateKey); if (!result.getAddress().equals(address)) { throw new IllegalArgumentException("Address not matching private key. Address: " + address + "; Address derived from private key: " + result.getAddress()); } return result; }
public static BitmessageAddress createIdentityFromPrivateKey(String address, byte[] privateSigningKey, byte[] privateEncryptionKey, long nonceTrialsPerByte, long extraBytes, int behaviourBitfield) { BitmessageAddress temp = new BitmessageAddress(address); PrivateKey privateKey = new PrivateKey(privateSigningKey, privateEncryptionKey, createPubkey(temp.getVersion(), temp.getStream(), cryptography().createPublicKey(privateSigningKey), cryptography().createPublicKey(privateEncryptionKey), nonceTrialsPerByte, extraBytes, behaviourBitfield)); BitmessageAddress result = new BitmessageAddress(privateKey); if (!result.getAddress().equals(address)) { throw new IllegalArgumentException("Address not matching private key. Address: " + address + "; Address derived from private key: " + result.getAddress()); } return result; }