Both sentences can be translated as
Ich darf nicht gehen.
The obvious problem with this sentence is that it cannot discern the two associated meanings because the position of nicht in clauses with a finite modal verb is always the same, whether nicht is negating the modal verb or its complement. However, the preferred interpretation of this sentence is such that darf is negated. It is very unusual, though possible–especially if aided by an emphasis of nicht–, to read this as negation of gehen.
There is a very common way to express the meaning of your second sentence, where the complement of the compound verb to be allowed to is negated. To do this, a different modal verb is employed, müssen. Normally, one would translate it to:
Ich muss nicht gehen.
The same type of ambiguity arises as in the first example and, again, in the most accessible interpretation it is understood that the modal verb is being negated. It would be really very unusual to deem nicht as negating gehen without any cause whatsoever that the context or other clues would have to supply.
So, to summarize, both sentences (with dürfen or müssen as finite verb) are ambiguous in that nicht can operate on the modal verb or its complement. The meaning of nicht differs in its scope. Let me call the first case outer negation and the second case inner negation. Furthermore, in both sentences the outer negation is the highly preferred interpretation. Therefore, you can use these two modal verbs to make the same distinction in German that is made by placing not at different places in English.
The reason why this can be expressed in this way in German is how the underlying modal logic operates and how the modal operators relate to German modal verbs. If we have two modal operators MAY and MUST, one negation NOT, and proposition A then there exist these equivalences:
NOT(MAY A) equals MUST(NOT A),
MAY(NOT A) equals NOT(MUST A).
Since each operator can be expressed by the other and the operator and proposition are negated in the process, two of these four expressions can be eschewed in favor of those with outer negation (marked in bold). This is similar to what happens in the use of the corresponding German modal verbs dürfen and müssen because a distinction of inner and outer negation by movement of nicht is not possible, i.e. the sentences are ambiguous, and one interpretation–the one with outer negation–is highly preferred.
If you want to translate to something closer to the source, you can translate allow to erlauben. This has the advantage of mirroring the English usage of not in front of what it is negating. It is also suggesting to some degree that there is a permission by someone absent (sentence 1) or present (sentence 2) and what its content is. (In the case of "Ich muss nicht A." there is no implication that someone has allowed to me not-A.) These are the respective translations:
Mir ist nicht erlaubt zu gehen.
Mir ist erlaubt nicht zu gehen.
Note that the English subject translates to a dative object and the infinitive clause ((nicht) zu gehen) is the subject.