Ok, Ill explain nK because I know this one a lot better. I've also realized a lot of confusion on what sanctions are, how they are enforced, and what we can and cant do with them. Im by no means an expert but I do have a decent grasp on some of this.
Sanctions can generally be unilateral, or cooperative. The strongest sanctions are cooperative sanctions backed by a UNSCR. This is the case of nK. The reason the UNSCR is important is because it gives the UN the authority to appoint a military commander to enforce the sanctions using military force. In the case of nK, the USINDOPACOM commander is the UNSCR commander and is authorized under the UN to enforce maritime trade against nK.
North Korea, operates a rice economy. In short, farm crops are traded for commodities more routinely than fiat currency. Under KJI, there was a massive military buildup through the 90s until his death. Specific of note he passed an ordinance through the party cabinet that allowed military commanders the authority to sequester a farmer's crops to feed their battalion. The problem is, this led to corruption, because more often than not, commanders were taking the crops to use as currency and not to feed the battalion. Obviously this caused a lot of starvation.
When KJU came to power, there were questions about his legitimacy, as it is with any ascension to power in a monarchy (or dictatorship, its not clear what nK is right now). This led KJU to consolidate power by purging but he also realized his father was deeply unpopular with the military and with the working class due to the mass hunger. So KJU led a massive expansion of internal economic expansion and gutted the military. The ONLY military capital he continued growth investment in was his nuclear and SOF forces. This was because DPRK probably assessed they can no longer win a conventional war against sK, even without US support. Therefore, asymmetric capabilities as deterrence became their only option.
To fuel this growth faster, KJU sought to bring an end to to the war by finally signing peace accords and permanently ending the UN mission to the Korean peninsula. (Different UN mission, this is the 1950's UN mission to maintain the armistice) This would have had major geopolitical effects on the peninsula, but in short he assessed he could further divest his military into the economy if he needed to. And its what brought nK to the talking table, in and of itself a major step.
The reason the peace talks failed is because nK was insistent that they maintain some nuclear capability because it was their country's only form of defense after gutting their forces. However, this is basically a red line for the US because as one of five benefactors of the NPT, we do not what other country's having nukes. We also we uncertain what allowing nK to continue to hold nuclear weapons would mean for other NPT signers who were not party to the talks.
That said, there is still hope. nK has temporarily withdrawn but their internal economic policies seem to still be in place.
Iran is a bit of a different story and I'm less smart on it. Iran was cooperative sanctions that were not backed by a UNSCR. So we relied on the participation of Germany, France the UK and a few other European traders to enforce the sanctions. This arrangement did work and also brought Iran to the talking table. Whether the agreement was good or not is immaterial now because it was simply the best agreement we were going to get. Withdrawing, in my opinion, was a massive mistake. The reason is because Europe largely supported the agreement and they were reluctant partners on the sanctions to begin with. So when we withdrew, the sanctions became unilateral and became near useless. Because of that, when we returned during this administration to the talking table, our bargaining leverage was extremely low. It is being reported by media that Iran is likely going to get away with a steal in this next agreement. I would say its shortsighted to say Iran didn't go our way though because it did go our way and then we withdrew from it.