Package java.security

Examples of java.security.MessageDigest


  protected byte[] createRequestAuthenticator(String sharedSecret) {
    byte[] secretBytes = RadiusUtil.getUtf8Bytes(sharedSecret);
    byte[] randomBytes = new byte[16];
    random.nextBytes(randomBytes);     

    MessageDigest md5 = getMd5Digest();
    md5.reset();
         md5.update(secretBytes);
         md5.update(randomBytes);
    return md5.digest();
  }
View Full Code Here


   * @param attributes encoded attributes of response packet
   * @param requestAuthenticator request packet authenticator
   * @return new 16 byte response authenticator
   */
  protected byte[] createResponseAuthenticator(String sharedSecret, int packetLength, byte[] attributes, byte[] requestAuthenticator) {
    MessageDigest md5 = getMd5Digest();
    md5.reset();
        md5.update((byte)getPacketType());
        md5.update((byte)getPacketIdentifier());
        md5.update((byte)(packetLength >> 8));
        md5.update((byte)(packetLength & 0x0ff));
        md5.update(requestAuthenticator, 0, requestAuthenticator.length);
        md5.update(attributes, 0, attributes.length);
        md5.update(RadiusUtil.getUtf8Bytes(sharedSecret));
        return md5.digest();   
  }
View Full Code Here

  protected byte[] updateRequestAuthenticator(String sharedSecret, int packetLength, byte[] attributes) {
    byte[] authenticator = new byte[16];
    for (int i = 0; i < 16; i++)
      authenticator[i] = 0;
   
    MessageDigest md5 = getMd5Digest();
        md5.reset();
        md5.update((byte)getPacketType());
        md5.update((byte)getPacketIdentifier());
        md5.update((byte)(packetLength >> 8));
        md5.update((byte)(packetLength & 0xff));
        md5.update(authenticator, 0, authenticator.length);
        md5.update(attributes, 0, attributes.length);
        md5.update(RadiusUtil.getUtf8Bytes(sharedSecret));
        return md5.digest();
  }
View Full Code Here

      for (int i = userPassBytes.length; i < encryptedPass.length; i++) {
          encryptedPass[i] = 0;
      }
 
      // digest shared secret and authenticator
      MessageDigest md5 = getMd5Digest();
    byte[] lastBlock = new byte[16];
   
    for (int i = 0; i < encryptedPass.length; i+=16) {
      md5.reset();
      md5.update(sharedSecret);
      md5.update(i == 0 ? getAuthenticator() : lastBlock);
      byte bn[] = md5.digest();
       
      System.arraycopy(encryptedPass, i, lastBlock, 0, 16);
   
      // perform the XOR as specified by RFC 2865.
      for (int j = 0; j < 16; j++)
View Full Code Here

      logger.warn("invalid Radius packet: User-Password attribute with malformed PAP password, length = " +
          encryptedPass.length + ", but length must be greater than 15");
      throw new RadiusException("malformed User-Password attribute");
    }
   
    MessageDigest md5 = getMd5Digest();
    byte[] lastBlock = new byte[16];
   
    for (int i = 0; i < encryptedPass.length; i+=16) {
      md5.reset();
      md5.update(sharedSecret);
      md5.update(i == 0 ? getAuthenticator() : lastBlock);
      byte bn[] = md5.digest();
       
      System.arraycopy(encryptedPass, i, lastBlock, 0, 16);
   
      // perform the XOR as specified by RFC 2865.
      for (int j = 0; j < 16; j++)
View Full Code Here

        // see RFC 2865 section 2.2
        byte chapIdentifier = (byte)random.nextInt(256);
        byte[] chapPassword = new byte[17];
        chapPassword[0] = chapIdentifier;

        MessageDigest md5 = getMd5Digest();
        md5.reset();
        md5.update(chapIdentifier);
        md5.update(RadiusUtil.getUtf8Bytes(plaintext));
        byte[] chapHash = md5.digest(chapChallenge);

        System.arraycopy(chapHash, 0, chapPassword, 1, 16);
        return chapPassword;
  }
View Full Code Here

      throw new RadiusException("CHAP challenge must be 16 bytes");
    if (chapPassword == null || chapPassword.length != 17)
      throw new RadiusException("CHAP password must be 17 bytes");
   
    byte chapIdentifier = chapPassword[0];
    MessageDigest md5 = getMd5Digest();
      md5.reset();
      md5.update(chapIdentifier);
      md5.update(RadiusUtil.getUtf8Bytes(plaintext));
      byte[] chapHash = md5.digest(chapChallenge);
     
      // compare
      for (int i = 0; i < 16; i++)
        if (chapHash[i] != chapPassword[i + 1])
          return false;
View Full Code Here

  protected byte[] updateRequestAuthenticator(String sharedSecret,
      int packetLength, byte[] attributes) {
    byte[] authenticator = new byte[16];
    for (int i = 0; i < 16; i++)
      authenticator[i] = 0;
    MessageDigest md5 = getMd5Digest();
    md5.reset();
    md5.update((byte) getPacketType());
    md5.update((byte) getPacketIdentifier());
    md5.update((byte) (packetLength >> 8));
    md5.update((byte) (packetLength & 0xff));
    md5.update(authenticator, 0, authenticator.length);
    md5.update(attributes, 0, attributes.length);
    md5.update(RadiusUtil.getUtf8Bytes(sharedSecret));
    return md5.digest();
  }
View Full Code Here

public class HashUtil {

  public static String getMD5(final String data) {
    try {
      MessageDigest m = MessageDigest.getInstance("MD5");
      m.reset();
      m.update(data.getBytes());
      BigInteger bigInt = new BigInteger(1, m.digest());
      String hashtext = bigInt.toString(16);
      while(hashtext.length() < 32 ){
          hashtext = "0" + hashtext;
      }
      return hashtext;
View Full Code Here

     * @throws java.lang.Exception
     */
    public static String encrypt( String text, String algName ) throws Exception {

      BASE64Encoder encoder = null;
      MessageDigest md      = null;
      encoder = new BASE64Encoder();
      md = MessageDigest.getInstance(algName);
      md.reset();
      md.update(text.getBytes());
      return encoder.encode(md.digest());

    }
View Full Code Here

TOP

Related Classes of java.security.MessageDigest

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.