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

3 REPLIES 3
akristiansson
Regular Visitor

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)

 

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.

View solution in original post

Helpful resources

Announcements
MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Top Solution Authors
Top Kudoed Authors