- Select square
- Activate direct select tool (a, white arrow, no this will not work with the black arrow*)
- move mouse to one of the corner points of the square.
- Once you snap to corner (be sure you have smart guides on) drag that corner so its on the line. (you may need to hold control down a bit depending on if the box is above or below the line)
- Activate rotate tool (r)
- Click on the corner, this moves the pivot there.
- Move to oppsite corner and drag untill your cursor snaps to line.
- Move back.
Animation 1: Screen capture of procedure above.
Alternate method draw a new line on top of the line with line tool. Alt click with line tool to get the angle. Rotate your grid to that angle. Redraw square.
* In general if you do not use the white arrow then you will have a very hard time doing a really big part of all that Illustrator does.