The present disclosure is directed at least in part to a method of producing ceramic layers on magnesium and its alloys a magnesium implant with a ceramic layer made by the method and a magnesium implant having a biocompatible ceramic layer substantially free of material which impairs the biocompatibility of said biocompatible ceramic layer. In an exemplary embodiment the method of producing ceramic layers on magnesium and its alloys includes (a) immersing an implant and a metal sheet into the aqueous electrolyte bath said aqueous electrolyte bath including: ammoniac diammonium hydrogen phosphate and urea and wherein the implant is made of magnesium or its alloy; (b) performing a anodic oxidation by passing a current between the implant the metal sheet and through the aqueous electrolyte bath wherein the implant is connected to a positive pole of a current source and the metal sheet is connected to a negative pole of the current source; (c) applying a current density selected to form sparks on said implant to thereby form a ceramic layer on said implant.