Examples of SHA1


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

  public static boolean verifySignature(byte[] message, DSASignature ds, DSAPublicKey dpk) throws IOException
  {
    /* Inspired by Bouncycastle's DSASigner class */

    SHA1 md = new SHA1();
    md.update(message);
    byte[] sha_message = new byte[md.getDigestLength()];
    md.digest(sha_message);

    BigInteger m = new BigInteger(1, sha_message);

    BigInteger r = ds.getR();
    BigInteger s = ds.getS();
View Full Code Here

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

    return v.equals(r);
  }

  public static DSASignature generateSignature(byte[] message, DSAPrivateKey pk, SecureRandom rnd)
  {
    SHA1 md = new SHA1();
    md.update(message);
    byte[] sha_message = new byte[md.getDigestLength()];
    md.digest(sha_message);

    BigInteger m = new BigInteger(1, sha_message);
    BigInteger k;
    int qBitLength = pk.getQ().bitLength();
View Full Code Here

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

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

    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

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

   * @param hostname
   * @return the hashed representation, e.g., "|1|cDhrv7zwEUV3k71CEPHnhHZezhA=|Xo+2y6rUXo2OIWRAYhBOIijbJMA="
   */
  public static final 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

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

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

  private static final 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);

    hmac.update(hostname.getBytes());
View Full Code Here

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

    catch (IOException e)
    {
      return false;
    }

    SHA1 sha1 = new SHA1();

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

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

    for (int i = 0; i < dig.length; i++)
View Full Code Here

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

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

    if ("ssh-rsa".equals(keyType))
View Full Code Here

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

   * @param hostname
   * @return the hashed representation, e.g., "|1|cDhrv7zwEUV3k71CEPHnhHZezhA=|Xo+2y6rUXo2OIWRAYhBOIijbJMA="
   */
  public static final 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

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

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

  private static final 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);

    hmac.update(hostname.getBytes());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.