web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Warning BP Rule::BPDeprecatedClassMethod: WinAPIServer::cryptUnProtectData has been deprecated and should not be used.

(0) ShareShare
ReportReport
Posted on by 1,552

Hi,

So i have this code on a certain table, to put a password field.

    /// 
    ///
    /// 
    public void insert()
    {
        Global::handleEncryptedTablePreInsert(this);
        super();
        Global::handleEncryptedTablePostInsert(this);
    }

    /// 
    ///
    /// 
    public void update()
    {
        Global::handleEncryptedTablePreUpdate(this);
        super();
        Global::handleEncryptedTablePostUpdate(this);
    }

    /// 
    ///
    /// 
    public edit Password passwordEdit(boolean _set, Password value)
    {
        if(_set)
        {
            this.ClientSecret = WinAPIServer::cryptProtectData(str2cryptoblob(value));
        }
        if(this.ClientSecret != conNull())
        {
            if(_set)
            {
                value = strRFix(value, strLen(value), 'X');
            }
            else 
            {
                value = 'XXXXXXXXX';
            }
        }
        return value;
    }

and in a certain class, i'm trying to get the password value by doing this

Password clientSecret  = cryptoblob2str(WinAPIServer::cryptUnProtectData(table.ClientSecret));

so i'm getting this BP warning on this line of code above?

what should i do? how to solve it?

Also i think after solving it i will get an error on the table method where i used cryptProtectData in the password edit method as shown above.

so how to solve it for both?

I have the same question (0)
  • Blue Wang Profile Picture
    on at
  • junior AX Profile Picture
    1,552 on at

    Hi Blue Wang,

    i just saw this. I'm not really familiar alot with .Net

    can you help me with what to replace cryptProtect and and cryptUnprotect?

  • Verified answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    You should use editEncryptedStringField() instead.

    For example, look at CatExternalCatalogProperties.editCatPropertyName().

  • junior AX Profile Picture
    1,552 on at

    Hi Martin,

    your example confused me a little because it seems, it depends on two fields name and value. while i only want to encypt the clientSecret field.

    unless i should replace propertyName with clientId field and replace value field with clientSecret.

    So should my method be like this:

        edit EncryptedString editClientSecret(boolean _set, EncryptedString _clientSecret)
        {
            return Global::editEncryptedStringField(this, _clientSecret, fieldNum(table, ClientSecret), _set);
        }

    or like this:

    edit ClientId editClientSecret(boolean _set, ClientId _clientId)
        {
            return Global::editEncryptedStringField(this, _clientId, fieldNum(table, ClientSecret), _set);
        }

    For now i chose the first option

    2. my clientSecret field was a container with EDT encryptedField. So i changed that to string with EDT encryptedString

    3. Also on the form i used dataMethod password edit. I changed this to editClientSecret

    4. i left what i put on insert and update as is [related to Global::handleEncryptedTablePreInsert(this); and Global::handleEncryptedTablePostInsert(this);

    But what i got is a big string field with not encrypted value, i want it to look like a password. What did i do wrong?

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    What do you mean by "it depends on two fields name and value"?

    Let me explain the example:

    edit CatPropertyName editCatPropertyName(boolean _set, CatPropertyName _propertyName)
    {
    	return Global::editEncryptedStringField(this, _propertyName, fieldNum(CatExternalCatalogProperties, Value), _set);
    }

    • _set says whether the edit method is setting a value or just retrieving it
    • if _set is true, _property is used to pass the new value (which is human-readable, i.e. unencrypted)
    • this is the table buffer you're getting the value from or setting to
    • and fieldNum(CatExternalCatalogProperties, Value) says which field is used for storing encrypted values

    Regarding your problem, did you try to debug your code? What did you find?

  • junior AX Profile Picture
    1,552 on at

    Hi Martin,

    Thanks

    When i debug i can see the the fieldNum is encrypted but the return value is the actual string(Ex: Hi , and not an encyrpted value). I want to see it as dots like password.

        edit EncryptedString editClientSecret(boolean _set, EncryptedString _clientSecret)
        {
            return Global::editEncryptedStringField(this, _clientSecret, fieldNum(table, ClientSecret), _set);
        }

  • Suggested answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    The purpose of this method is displaying human-readable values in GUI and store them encrypted in database.

    If your goal isn't displaying the value, simply don't do it. Return '*****', for example, instead of the value.

  • junior AX Profile Picture
    1,552 on at

    Hi Martin,

    But i want it to be password so that i can see the value the first time (the eye next to the password).

    can't i keep using it?  without Winapiserver?

    Also how to decrypt. the BP warning was on this

    Password clientSecret  = cryptoblob2str(WinAPIServer::cryptUnProtectData(table.ClientSecret));

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Using a different encryption algorithm doesn't change your GUI design. That's a completely different problem.

    I believe we've resolved the topic of this thread and you should know now how to replace cryptUnProtectData() (which resolves BPDeprecatedClassMethod).

  • junior AX Profile Picture
    1,552 on at

    Hi Martin,

    I was getting the BP warning on this:

    Password clientSecret  = cryptoblob2str(WinAPIServer::cryptUnProtectData(table.ClientSecret));

    I thought what you suggested below was for cryptProtectData (related to my edit password method) not UnProtect

    are you saying that i should use this

    Global::editEncryptedStringField(this, _clientSecret, fieldNum(table, ClientSecret)

    instead of

    cryptoblob2str(WinAPIServer::cryptUnProtectData(table.ClientSecret));

    and not instead my passwordEdit method?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 551 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans