src/main/java/org/tinyradius/packet/AccessRequest.java
private byte[] encodePapPassword(final byte[] userPass, byte[] sharedSecret) {
        // the password must be a multiple of 16 bytes and less than or equal
        // to 128 bytes. If it isn't a multiple of 16 bytes fill it out with zeroes
        // to make it a multiple of 16 bytes. If it is greater than 128 bytes
        // truncate it at 128.
        byte[] userPassBytes = null;
        if (userPass.length > 128) {
            userPassBytes = new byte[128];
            System.arraycopy(userPass, 0, userPassBytes, 0, 128);
        }
        else {
            userPassBytes = userPass;
        }

        // declare the byte array to hold the final product
        byte[] encryptedPass = null;
        if (userPassBytes.length < 128) {
            if (userPassBytes.length % 16 == 0) {
                // tt is already a multiple of 16 bytes
                encryptedPass = new byte[userPassBytes.length];
            }
            else {
                // make it a multiple of 16 bytes
                encryptedPass = new byte[((userPassBytes.length / 16) * 16) + 16];
            }
        }
        else {
            // the encrypted password must be between 16 and 128 bytes
            encryptedPass = new byte[128];
        }

        // copy the userPass into the encrypted pass and then fill it out with zeroes
        System.arraycopy(userPassBytes, 0, encryptedPass, 0, userPassBytes.length);
        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++) {
                encryptedPass[i + j] = (byte) (bn[j] ^ encryptedPass[i + j]);
            }
        }

        return encryptedPass;
    }
/**
     * This method encodes the plaintext user password according to RFC 2865.
     *
     * @param userPass     the password to encrypt
     * @param sharedSecret shared secret
     * @return the byte array containing the encrypted password
     */
This method encodes the plaintext user password according to RFC 2865.

@param userPass     the password to encrypt
@param sharedSecret shared secret
@return the byte array containing the encrypted password
This method encodes the plaintext user password according to RFC 2865 . @param userPass the password to encrypt @param sharedSecret shared secret @return the byte array containing the encrypted password
private byte[] encodePapPassword(final byte[] userPass, byte[] sharedSecret) {
        byte[] userPassBytes = null;
        if (userPass.length > 128) {
            userPassBytes = new byte[128];
            System.arraycopy(userPass, 0, userPassBytes, 0, 128);
        }
        else {
            userPassBytes = userPass;
        }
        byte[] encryptedPass = null;
        if (userPassBytes.length < 128) {
            if (userPassBytes.length % 16 == 0) {
                encryptedPass = new byte[userPassBytes.length];
            }
            else {
                encryptedPass = new byte[((userPassBytes.length / 16) * 16) + 16];
            }
        }
        else {
            encryptedPass = new byte[128];
        }
        System.arraycopy(userPassBytes, 0, encryptedPass, 0, userPassBytes.length);
        for (int i = userPassBytes.length; i < encryptedPass.length; i++) {
            encryptedPass[i] = 0;
        }
        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);
            for (int j = 0; j < 16; j++) {
                encryptedPass[i + j] = (byte) (bn[j] ^ encryptedPass[i + j]);
            }
        }
        return encryptedPass;
    }
private byte [ ] encodePapPassword ( final byte [ ] userPass , byte [ ] sharedSecret ) { byte [ ] userPassBytes = null ; if ( userPass . length > 128 ) { userPassBytes = new byte [ 128 ] ; System . arraycopy ( userPass , 0 , userPassBytes , 0 , 128 ) ; } else { userPassBytes = userPass ; } byte [ ] encryptedPass = null ; if ( userPassBytes . length < 128 ) { if ( userPassBytes . length % 16 == 0 ) { encryptedPass = new byte [ userPassBytes . length ] ; } else { encryptedPass = new byte [ ( ( userPassBytes . length / 16 ) * 16 ) + 16 ] ; } } else { encryptedPass = new byte [ 128 ] ; } System . arraycopy ( userPassBytes , 0 , encryptedPass , 0 , userPassBytes . length ) ; for ( int i = userPassBytes . length ; i < encryptedPass . length ; i ++ ) { encryptedPass [ i ] = 0 ; } 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 ) ; for ( int j = 0 ; j < 16 ; j ++ ) { encryptedPass [ i + j ] = ( byte ) ( bn [ j ] ^ encryptedPass [ i + j ] ) ; } } return encryptedPass ; }
This method encodes the plaintext user password according to RFC 2865.
This method encodes the plaintext user password according to RFC 2865 .
// the password must be a multiple of 16 bytes and less than or equal
 // to 128 bytes. If it isn't a multiple of 16 bytes fill it out with zeroes
 // to make it a multiple of 16 bytes. If it is greater than 128 bytes
 // truncate it at 128.
 // declare the byte array to hold the final product
 // tt is already a multiple of 16 bytes
 // make it a multiple of 16 bytes
 // the encrypted password must be between 16 and 128 bytes
 // copy the userPass into the encrypted pass and then fill it out with zeroes
 // digest shared secret and authenticator
 // perform the XOR as specified by RFC 2865.
