cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
eddydm
Helper III
Helper III

Privacy - Hashing of keys

Hey,

 

 

In a powerbi-file i have some related tables. Some of the relations uses a key which contains specific personal-related-information, which may not be visable to 'the whole world' (privacy rules.)

I want to hash this key and use this hashed values in the relations.

 

Some questions:

* is the hashing of the key possible?

* Can some give me an example how to calculate this hashing. I like to use dax-formulas, not the r-scripting.

 

 

Kind regards

 

 

Eddy

 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @eddydm,

 

I haven't find any function to directly convert the string to hash string (dax and power query not contain).

 

For your requirement, you can try to use below methods if it works on your side:

 

1. T-sql.

 

Use a static string to instead of the privacy information or use hasbytes to transform.

 

Capture.PNG

 

2. R script.

Write a r script which use to convert the string, then run it in query editor.

 

3. Web.Content.

Add a custom step which use to call a transform string api/webservice.

 

Reference links:

HASHBYTES (Transact-SQL)

Using R in Query Editor

Web.Contents

Power Query Functions–Some Scenarios

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

5 REPLIES 5
akristiansson
Advocate I
Advocate I

Old thread, but I had a similar need and I've found a pure Power Query/M solution to this...

 

M can compress binary data as gzip, the gzip footer contains a 32-bit CRC checksum which we can access and use as a uniformly sized hash:

 

CalculateHash = (x as text) as number => BinaryFormat.UnsignedInteger32(
    Binary.FromList(
        List.FirstN(
            List.LastN(
                Binary.ToList(
                    Binary.Compress(Text.ToBinary(x, BinaryEncoding.Base64), Compression.GZip)
                ),
            8), 
        4)
    )
)

The footer is 8 bytes, the first 4 of which contains the checksum. We convert the gzip binary to a list in order to extract the relevant bytes and in turn convert this to a non-negative number. Alternatively, you could use the hex value for a text hash:

 

CalculateHash = (x as text) as text => Binary.ToText(
    Binary.FromList(
        List.FirstN(
            List.LastN(
                Binary.ToList(
                    Binary.Compress(Text.ToBinary(x, BinaryEncoding.Base64), Compression.GZip)
                ),
            8), 
        4)
     ),
BinaryEncoding.Hex)

 

This is a brilliant answer

I need user Hash md5. Can I do it on Power Bi witch M language.

The post by akristiansson is highly useful but it might be easier for typical users if Perfect Hash Functions were implemented in Power BI [1] out-of-the-box so the users would not have to resort to Power Query M:
https://crypto.stackexchange.com/questions/8765/is-there-a-hash-function-which-has-no-collisions/212...

From a personal standpoint, I should be able to figure out how to apply akristiansson's method; unfortunately, I'm not sure if the "average" Power BI users are going to want to do that everytime they import sensitive Row Ids.  When users import data into Power BI, they should be given an option to supply a key that will automatically Perfectly Hash the senstive colums (without collisions) before they are loaded into Power BI.  The users would then be responsible for safeguarding that key in case they ever need to apply the Perfect Hash for future imports of related data.

[1] - Also, assuming the datasource is an onsite MS SQL Server, it's posible that MS SQL Server could be modified to apply the Perfect Hash to the senstive colums before they are loaded into Power BI and/or read by DirectQuery.

 

v-shex-msft
Community Support
Community Support

Hi @eddydm,

 

I haven't find any function to directly convert the string to hash string (dax and power query not contain).

 

For your requirement, you can try to use below methods if it works on your side:

 

1. T-sql.

 

Use a static string to instead of the privacy information or use hasbytes to transform.

 

Capture.PNG

 

2. R script.

Write a r script which use to convert the string, then run it in query editor.

 

3. Web.Content.

Add a custom step which use to call a transform string api/webservice.

 

Reference links:

HASHBYTES (Transact-SQL)

Using R in Query Editor

Web.Contents

Power Query Functions–Some Scenarios

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 24 without aka link and time 768x460.jpg

Ted's Dev Camp - July 28, 2022

Watch Session 24 of Ted's Dev Camp along with past sessions!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors