When used as synonyms, the difference is 'but' is informal and used in spoken English, 'however' is formal and used in written English. Punctuation is also different ('I'd like to, but I can't' and 'I'd like to; however, I can't'). There is no other real difference if they are used as synonyms.