Package com.bitsofproof.supernode.common

Examples of com.bitsofproof.supernode.common.ValidationException


    {
      seed = Arrays.copyOfRange (raw, 9, 64 + 9);
    }
    else
    {
      throw new ValidationException ("Not an encoded HD root");
    }
    ExtendedKey key = ExtendedKey.create (seed);
    if ( !Arrays.equals (Arrays.copyOf (Hash.hash (key.getMaster ().getPrivate ()), 4), Arrays.copyOfRange (raw, 5, 9)) )
    {
      throw new ValidationException ("HD root checksum error");
    }
    return key;
  }
View Full Code Here


      encryptedSeed = Arrays.copyOfRange (raw, 9, 64 + 9);
      N = 1 << 18;
    }
    else
    {
      throw new ValidationException ("Not an encoded HD root");
    }
    byte salt[] = Arrays.copyOf (raw, 9);

    Mac mac;
    try
    {
      mac = Mac.getInstance ("HmacSHA512", "BC");
      SecretKey seedkey = new SecretKeySpec (salt, "HmacSHA512");
      mac.init (seedkey);
      byte[] preH = mac.doFinal (passphrase.getBytes ("UTF-8"));
      byte[] strongH = SCrypt.generate (preH, preH, N, r, p, 64);
      seedkey = new SecretKeySpec (passphrase.getBytes ("UTF-8"), "HmacSHA512");
      mac.init (seedkey);
      byte[] postH = mac.doFinal (salt);
      byte[] H = SCrypt.generate (postH, strongH, 1 << 10, 1, 1, encryptedSeed.length + 32);
      byte[] X = Arrays.copyOf (H, encryptedSeed.length);
      SecretKeySpec keyspec = new SecretKeySpec (Arrays.copyOfRange (H, encryptedSeed.length, encryptedSeed.length + 32), "AES");
      Cipher cipher = Cipher.getInstance ("AES/ECB/NoPadding", "BC");
      cipher.init (Cipher.DECRYPT_MODE, keyspec);
      byte[] seed = cipher.doFinal (encryptedSeed);
      for ( int i = 0; i < encryptedSeed.length; ++i )
      {
        seed[i] ^= X[i];
      }
      ExtendedKey key = ExtendedKey.create (seed);
      if ( !Arrays.equals (Arrays.copyOf (Hash.hash (key.getMaster ().getPrivate ()), 4), Arrays.copyOfRange (raw, 5, 9)) )
      {
        throw new ValidationException ("HD root checksum error");
      }
      return key;
    }
    catch ( NoSuchAlgorithmException | NoSuchProviderException | InvalidKeyException | UnsupportedEncodingException | NoSuchPaddingException
        | IllegalBlockSizeException | BadPaddingException e )
    {
      throw new ValidationException (e);
    }
  }
View Full Code Here

  public static String encode (byte[] seed, Date birth) throws ValidationException
  {
    if ( seed == null || (seed.length != 16 && seed.length != 32 && seed.length != 64) )
    {
      throw new ValidationException ("Seed must be 16, 32 or 64 bytes");
    }
    int weeks =
        (int) ((birth.getTime () - new GregorianCalendar (2013, Calendar.JANUARY, 1).getTime ().getTime ()) / (7 * 24 * 60 * 60 * 1000L));

    ExtendedKey key = ExtendedKey.create (seed);
View Full Code Here

  public static String encrypt (byte[] seed, Date birth, String passphrase, ScryptDifficulty scryptDifficulty) throws ValidationException
  {
    if ( seed == null || (seed.length != 16 && seed.length != 32 && seed.length != 64) )
    {
      throw new ValidationException ("Seed must be 16, 32 or 64 bytes");
    }
    int weeks =
        (int) ((birth.getTime () - new GregorianCalendar (2013, Calendar.JANUARY, 1).getTime ().getTime ()) / (7 * 24 * 60 * 60 * 1000L));

    ExtendedKey key = ExtendedKey.create (seed);
    byte raw[];
    byte[] salt = new byte[9];
    if ( seed.length == 16 )
    {
      raw = new byte[25];
      System.arraycopy (encrypted16, 0, salt, 0, 3);
    }
    else if ( seed.length == 32 )
    {
      raw = new byte[41];
      System.arraycopy (encrypted32, 0, salt, 0, 3);
    }
    else
    {
      raw = new byte[73];
      System.arraycopy (encrypted64, 0, salt, 0, 3);
    }
    salt[2] += scryptDifficulty.ordinal ();
    salt[3] = (byte) (weeks & 0xff);
    salt[4] = (byte) ((weeks >>> 8) & 0xff);
    System.arraycopy (Hash.hash (key.getMaster ().getPrivate ()), 0, salt, 5, 4);
    System.arraycopy (salt, 0, raw, 0, 9);
    int N = (1 << 14) << (scryptDifficulty.ordinal () * 2);
    int r = scryptDifficulty == ScryptDifficulty.LOW ? 8 : 16;
    int p = scryptDifficulty == ScryptDifficulty.LOW ? 8 : 16;
    Mac mac;
    try
    {
      mac = Mac.getInstance ("HmacSHA512", "BC");
      SecretKey seedkey = new SecretKeySpec (salt, "HmacSHA512");
      mac.init (seedkey);
      byte[] preH = mac.doFinal (passphrase.getBytes ("UTF-8"));
      byte[] strongH = SCrypt.generate (preH, preH, N, r, p, 64);
      seedkey = new SecretKeySpec (passphrase.getBytes ("UTF-8"), "HmacSHA512");
      mac.init (seedkey);
      byte[] postH = mac.doFinal (salt);
      byte[] H = SCrypt.generate (postH, strongH, 1 << 10, 1, 1, seed.length + 32);
      byte[] X = Arrays.copyOf (H, seed.length);
      for ( int i = 0; i < seed.length; ++i )
      {
        X[i] ^= seed[i];
      }
      SecretKeySpec keyspec = new SecretKeySpec (Arrays.copyOfRange (H, seed.length, seed.length + 32), "AES");
      Cipher cipher = Cipher.getInstance ("AES/ECB/NoPadding", "BC");
      cipher.init (Cipher.ENCRYPT_MODE, keyspec);
      System.arraycopy (cipher.doFinal (X), 0, raw, 9, seed.length);
    }
    catch ( NoSuchAlgorithmException | NoSuchProviderException | InvalidKeyException | UnsupportedEncodingException | NoSuchPaddingException
        | IllegalBlockSizeException | BadPaddingException e )
    {
      throw new ValidationException (e);
    }
    return ByteUtils.toBase58WithChecksum (raw);
  }
View Full Code Here

  public void unlock (String passphrase) throws ValidationException
  {
    master = ExtendedKey.createFromPassphrase (passphrase, encrypted);
    if ( !master.getMaster ().verify (encrypted, signature) )
    {
      throw new ValidationException ("incorrect passphrase");
    }
    for ( NCExtendedKeyAccountManager account : accounts.values () )
    {
      account.setMaster (master.getChild (account.getMaster ().getSequence ()));
    }
View Full Code Here

    }
    else
    {
      if ( master == null )
      {
        throw new ValidationException ("The wallet is locked");
      }
      NCExtendedKeyAccountManager account = new NCExtendedKeyAccountManager (name, Math.min (System.currentTimeMillis (), since));
      account.setMaster (master.getChild (accounts.size () | 0x80000000));
      accounts.put (name, account);
      return account;
View Full Code Here

  public void addKey (String name, ExtendedKey key, long created) throws ValidationException
  {
    if ( accountManager.containsKey (name) )
    {
      throw new ValidationException (name + " account manager exsists");
    }
    ExtendedKeyAccountManager manager;
    accountManager.put (name, manager = new ExtendedKeyAccountManager ());
    manager.setMaster (key);
  }
View Full Code Here

  @Override
  public AccountManager createAccountManager (String name) throws ValidationException
  {
    if ( accountManager.containsKey (name) )
    {
      throw new ValidationException (name + " account manager exsists");
    }
    ExtendedKeyAccountManager manager;
    accountManager.put (name, manager = new ExtendedKeyAccountManager ());
    manager.setMaster (ExtendedKey.createNew ());
    return manager;
View Full Code Here

  public static SecretShare[] cut (byte[] secret, int pieces, int needed) throws ValidationException
  {
    if ( secret.length > 127 )
    {
      throw new ValidationException ("secret too long");
    }
    BigInteger[] coeff = new BigInteger[needed - 1];
    for ( int i = 0; i < coeff.length; ++i )
    {
      byte[] r = new byte[secret.length];
View Full Code Here

    {
      for ( int j = 0; j < shares.length; ++j )
      {
        if ( i != j && shares[i].x == shares[j].x )
        {
          throw new ValidationException ("Shares are not unique");
        }
      }
    }
    BigInteger[] y = new BigInteger[shares.length];
    for ( int i = 0; i < shares.length; ++i )
View Full Code Here

TOP

Related Classes of com.bitsofproof.supernode.common.ValidationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.