Package ch.ethz.ssh2.crypto.digest

Examples of ch.ethz.ssh2.crypto.digest.SHA1


    return tw.getBytes();
  }

  public static RSASignature generateSignature(byte[] message, RSAPrivateKey pk) throws IOException
  {
    SHA1 md = new SHA1();
    md.update(message);
    byte[] sha_message = new byte[md.getDigestLength()];
    md.digest(sha_message);

    byte[] der_header = new byte[] { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00,
        0x04, 0x14 };

    int rsa_block_len = (pk.getN().bitLength() + 7) / 8;
View Full Code Here


    return new RSASignature(s);
  }

  public static boolean verifySignature(byte[] message, RSASignature ds, RSAPublicKey dpk) throws IOException
  {
    SHA1 md = new SHA1();
    md.update(message);
    byte[] sha_message = new byte[md.getDigestLength()];
    md.digest(sha_message);

    BigInteger n = dpk.getN();
    BigInteger e = dpk.getE();
    BigInteger s = ds.getS();
View Full Code Here

   * @param hostname
   * @return the hashed representation, e.g., "|1|cDhrv7zwEUV3k71CEPHnhHZezhA=|Xo+2y6rUXo2OIWRAYhBOIijbJMA="
   */
  public static String createHashedHostname(String hostname)
  {
    SHA1 sha1 = new SHA1();

    byte[] salt = new byte[sha1.getDigestLength()];

    new SecureRandom().nextBytes(salt);

    byte[] hash = hmacSha1Hash(salt, hostname);

View Full Code Here

    return new String("|1|" + base64_salt + "|" + base64_hash);
  }

  private static byte[] hmacSha1Hash(byte[] salt, String hostname)
  {
    SHA1 sha1 = new SHA1();

    if (salt.length != sha1.getDigestLength())
    {
      throw new IllegalArgumentException("Salt has wrong length (" + salt.length + ")");
    }

    HMAC hmac = new HMAC(sha1, salt, salt.length);
View Full Code Here

    catch (IOException e)
    {
      return false;
    }

    SHA1 sha1 = new SHA1();

    if (salt.length != sha1.getDigestLength())
    {
      return false;
    }

    byte[] dig = hmacSha1Hash(salt, hostname);
View Full Code Here

    {
      dig = new MD5();
    }
    else if ("sha1".equals(type))
    {
      dig = new SHA1();
    }
    else
    {
      throw new IllegalArgumentException("Unknown hash type " + type);
    }
View Full Code Here

      PacketUserauthRequestNone urn = new PacketUserauthRequestNone("ssh-connection", user);
      tm.sendMessage(urn.getPayload());

      byte[] msg = getNextMessage();
      new PacketServiceAccept(msg, 0, msg.length);
      msg = getNextMessage();

      initDone = true;

      if (msg[0] == Packets.SSH_MSG_USERAUTH_SUCCESS)
View Full Code Here

  {
    if (initDone == false)
    {
      tm.registerMessageHandler(this, 0, 255);

      PacketServiceRequest sr = new PacketServiceRequest("ssh-userauth");
      tm.sendMessage(sr.getPayload());

      PacketUserauthRequestNone urn = new PacketUserauthRequestNone("ssh-connection", user);
      tm.sendMessage(urn.getPayload());

      byte[] msg = getNextMessage();
View Full Code Here

      byte[] msg = deQueue();

      if (msg[0] != Packets.SSH_MSG_USERAUTH_BANNER)
        return msg;

      PacketUserauthBanner sb = new PacketUserauthBanner(msg, 0, msg.length);

      banner = sb.getBanner();
    }
  }
View Full Code Here

        return true;
      }

      if (msg[0] == Packets.SSH_MSG_USERAUTH_FAILURE)
      {
        PacketUserauthFailure puf = new PacketUserauthFailure(msg, 0, msg.length);

        remainingMethods = puf.getAuthThatCanContinue();
        isPartialSuccess = puf.isPartialSuccess();
        return false;
      }

      throw new IOException("Unexpected SSH message (type " + msg[0] + ")");
    }
View Full Code Here

TOP

Related Classes of ch.ethz.ssh2.crypto.digest.SHA1

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.