def create_dmcrypt_key():
    """
    Create the secret dm-crypt key used to decrypt a device.
    """
    # get the customizable dmcrypt key size (in bits) from ceph.conf fallback
    # to the default of 1024
    dmcrypt_key_size = conf.ceph.get_safe(
        'osd',
        'osd_dmcrypt_key_size',
        default=1024,
    )
    # The size of the key is defined in bits, so we must transform that
    # value to bytes (dividing by 8) because we read in bytes, not bits
    random_string = os.urandom(int(dmcrypt_key_size / 8))
    key = base64.b64encode(random_string).decode('utf-8')
    return key