def sign_data(priv_key, data, encoded=True):
    """
    Create a signature for a set of data using private key
    :param priv_key: Private key
    :param data: String data that the signature is being created for
    :param encoded: Boolean. True for base64 encoded data input
    False for raw data input
    :return: Base64 encoded signature
    """
    from Crypto.PublicKey import RSA
    from Crypto.Signature import PKCS1_v1_5
    from Crypto.Hash import SHA256
    from base64 import b64encode, b64decode
    rsakey = RSA.importKey(priv_key)
    signer = PKCS1_v1_5.new(rsakey)
    digest = SHA256.new()
    if encoded:
        digest.update(b64decode(data))
    else:
        digest.update(data)
    sign = signer.sign(digest)
    return b64encode(sign).decode('unicode_escape')
