BERLIN — Two young hackers were convicted in Germany Thursday of stealing new songs from stars such as Lady Gaga and Mariah Carey and offering them for sale on the Internet, a court said.

The local court in the western city of Duisburg found the defendants, aged 18 and 23, guilty of dozens of counts of violating copyrights and hacking confidential data, a spokesman said. Their names were not released.

The teenager was handed an 18-month sentence at a young offenders' institute while the older defendant received an 18-month suspended sentence.

The two used Trojan horse software to gain access to the computers and e-mail accounts of the managers of high-profile artists, took unpublished songs and offered them for sale or download in 2009 and 2010.

The new material came from top-selling stars including Carey, Lady Gaga, Justin Timberlake, Leona Lewis and Kesha, the court said. Prosecutors say the two earned more than 15,000 euros ($21,000) with the scheme.

In addition, the 18-year-old downloaded explicit private photos from Kesha's computer and blackmailed her to give him an audio "shout out" which he could use to boost his own status in the hacker scene.

"The court considered the fact that both defendants are attested to be highly addicted to the Internet to be a mitigating factor," the spokesman told AFP, adding that full confessions given to the court had also counted in their favour.

Defence attorneys had asked the court to call the affected artists as witnesses but the judges rejected the bid.

The 18-year-old, identified in the German press only as Deniz A., had sent a letter of apology to Lady Gaga in December that was published in the daily Bild.

"Dear Lady Gaga," Deniz A., who reportedly called himself DJ Stolen, wrote.

"I am ashamed of what I have done. I did not think about the consequences."

The court said it would review his detention within six months and consider converting it to a suspended sentence.