For finding chords to melodies, there's just one word: practice. There's no other way. There's no substitute for hearing and feeling. Forget about the "this note, so this chord" magic cheat idea. In some cases tricks like that can be applied, but it would still only improve your hit rate from "completely random" to "not completely random" level. Would you be happy if you could recognize your friend's face in a crowd even as much as 60 % of time, using some trick?
Learning the skill consists of two parts: (1) producing i.e. playing, and (2) listening. To play "by ear" means listening to an example and trying to answer the question "what would I play to make it sound like that".
To answer that question successfully immediately after hearing something, you have to have played many things and heard what they sound like many, many times, in many different contexts. When you're not very skilled and experienced yet, you'll have a narrower and less familiar palette of things to try, so there'll be more trial and error. If it doesn't sound like what you wanted, try something else. Keep practicing and you will get better. Your musical palette will expand, and the "hit rate" will improve.
Here are some exercises and hints to try:
Find the melody and chords to simple songs by ear. "London Bridge is Falling Down", "Twinkle, Twinkle, Little Start", "Happy Birthday", "Hit the Road, Jack", etc. First in a familiar key, like C major, and then do the same in other keys.
For finding the key, locate the home base note ("tonal center" or whatever). Some people try to explain what the tonal center feels like, but you have to learn to feel it. You gradually learn what it feels like by playing simple songs in different keys. In the key of C, what does the C note feel like? In the key of C, the home base is C. In the key of F, the home base is F. Learn to know what F feels like, when you're playing a song in F.
To establish a key, play a I - IV - V - I cadence.
- To establish the key of C major, play the chords: C - F - G - C.
- To establish the key of F major (key signature: 1 flat), play the chords: F - Bb - C - F.
- To establish the key of G major (key signature: 1 sharp), play the chords: G - C - D - G.
- To establish the key of A minor, play the chords: Am - Dm - E - Am.
- etc.
(That's also a clear way to start a song. First play a I - IV - V - I cadence, and play the song's starting pitch and chord, before the singer starts singing. ;))
To play a simple song in a new key, first establish the key (see above), and then find the melody and accompanying chords by ear. Repeat. At first it is hard, but you'll get better at it. No gain without pain.
To find a melody by ear, you have to have a reference to compare to, so it has to be a song you know well. Play, listen, compare.
To find chords by ear: trial and error, lots of trial and error. Play simple songs that can be played with e.g. I/IV/V i.e. C, F and G major chords in the key of C major. Try each chord and listen. Maybe someone should pick "safe" songs for you to practice with, but in any case, there has to be a lot of "babbling" like what babies do when they start learning to speak. When you're a grown-up, you'd like to skip that embarrassing phase, and jump straight to respected legitimate things, but no can do.
You have to know what a "I chord" feels like, what a "IV chord" fees like, what a "V chord" feels like, etc. Does something feel like a V chord? Does it feel like a I chord? If you don't get any such feelings, then you haven't practiced enough. Practice more.
Like Tim says in his answer, a good bread-and-butter set of chords is, three chords of the major key and three chords of the minor key. For songs in the key of C major / A minor (key signature: no sharps/flats, white keys) they would be, C, F, G, Am, Dm, E (i.e. G sharp in that chord, E-G#-B). Babble with those six chords, and try to accompany melodies you know with them.
To learn to identify and analyze the things you're hearing, alter the components (notes) and listen to what the changes do. Play the notes of chords one at a time, leave out a note, move a note up or down, etc.
To get more ideas about things to try, check out song books (lead sheets) and try to understand the role of each chord. I, IV, V, ii, vi, etc. When you see an accidental in the melody, there's probably a temporary scale change that's also reflected in the chords. For example, in a song that's in A minor key (key signature: white keys), there might be an A major chord before going to a Dm, and the melody must take that into account and play a C# instead of C. Or there might be a Gm and A7 before going to the Dm, both of which have "non-white keys". Tricks like this are common in songs, but trying those chords in that context might not cross your mind by just randomly poking at chords.