public static ECDSASignature sign(@NonNull final byte[] hash,
			@NonNull final ECKey key) {
		final BigInteger d = key.getPrivateKey();
		if (d == null) {
			throw new IllegalArgumentException(
					"A private key is required to sign a message"); //$NON-NLS-1$
		}

		// 1. Calculate e = HASH(message)
		// 2. and Let z be the n.bitLength() leftmost bits of e.
		final BigInteger z = calculateZ(hash);

		BigInteger r = BigInteger.ZERO;
		BigInteger s = BigInteger.ZERO;
		do {
			BigInteger k;
			do {
				// 3. Select a random integer k in the interval [1, n-1].
				do {
					k = new BigInteger(256, SECURE_RANDOM);
				} while (k.equals(BigInteger.ZERO) || k.compareTo(N) >= 0);

				// 4. Calculate the curve point u(x,y)=k*G
				final ECPoint u = G.multiply(k);

				// 5. Calculate r=x % n. If r==0, go back to step 3.
				final ECFieldElement vx = u.getX();
				if (vx != null) {
					r = vx.toBigInteger().mod(N);
				}
			} while (r.equals(BigInteger.ZERO));

			// 6. Calculate s = k^-1(z+r d). if s==0, go back to step 3.
			s = k.modInverse(N).multiply(z.add(d.multiply(r))).mod(N);
		} while (s.equals(BigInteger.ZERO));
		return new ECDSASignature(r, s);
	}