简体   繁体   中英

How to get cryptographically secure randomness with c++/cx on Windows Phone?

So apparently there is the System.Security.Cryptography.RNGCryptoServiceProvider class available in .NET . But it's my understanding (I'm new to windows phone 8 development) that I can't access that function from c++/cx... or can I?

I've not been able to find any other function/class in the Windows Phone API that I might use. What am I missing?

I found that I could actually use the WinRT Windows.Security.Cryptography API from c++/cx.

The solution was to simply

auto iBuffer = Windows::Security::Cryptography::CryptographicBuffer::GenerateRandom(rand_len);

To get the data from the iBuffer I used this answer :

auto reader = Windows::Storage::Streams::DataReader::FromBuffer(iBuffer);
std::vector<unsigned char> data(reader->UnconsumedBufferLength);
if (!data.empty())
    reader->ReadBytes(
        ::Platform::ArrayReference<unsigned char>(
            &data[0], data.size()
        )
    );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM