locked
IBufferByteAccess and the PackageSpecificToken

    Question

  • Any ideas on getting the bytestream from PackageSpecificToken? If you do:

    var deviceToken = Windows.System.Profile.HardwareIdentification.getPackageSpecificToken(null);

    deviceId = deviceToken;

    then DeviceId is an IBuffer. No clue how to get the bytes from it in JavaScript. Thoughts?

    S


    Check out my new C# 2010 All In One for Dummies book at Amazon!

    Friday, August 17, 2012 3:39 PM

Answers

  • Here you go:

        var packageSpecificToken;
    
                packageSpecificToken = Windows.System.Profile.HardwareIdentification.getPackageSpecificToken(null);
    
                // hardware id, signature, certificate IBuffer objects 
                // that can be accessed through properties.
                var hardwareId = packageSpecificToken.id;
                var signature = packageSpecificToken.signature;
                var certificate = packageSpecificToken.certificate;
                var dataReader = Windows.Storage.Streams.DataReader.fromBuffer(hardwareId);
    
                var array = new Array(hardwareId.length);
                dataReader.readBytes(array);

    -Jeff

    Jeff Sanders (MSFT)

    Friday, August 17, 2012 5:20 PM
    Moderator

All replies

  • Friday, August 17, 2012 3:55 PM
    Moderator
  • Say No Such Interface Supported when I try and create the DataReader.

        var deviceToken = Windows.System.Profile.HardwareIdentification.getPackageSpecificToken(null);
        var deviceBuffer = deviceToken.id; //This is an iBuffer

        var reader = new Windows.Storage.Streams.DataReader(deviceBuffer);
       reader.loadAsync(deviceBuffer.length).then(
       function (readsize) {
           var array = new Array(readsize);
           reader.readBytes(array);
       });


    Check out my new C# 2010 All In One for Dummies book at Amazon!

    Friday, August 17, 2012 4:07 PM
  • Here you go:

        var packageSpecificToken;
    
                packageSpecificToken = Windows.System.Profile.HardwareIdentification.getPackageSpecificToken(null);
    
                // hardware id, signature, certificate IBuffer objects 
                // that can be accessed through properties.
                var hardwareId = packageSpecificToken.id;
                var signature = packageSpecificToken.signature;
                var certificate = packageSpecificToken.certificate;
                var dataReader = Windows.Storage.Streams.DataReader.fromBuffer(hardwareId);
    
                var array = new Array(hardwareId.length);
                dataReader.readBytes(array);

    -Jeff

    Jeff Sanders (MSFT)

    Friday, August 17, 2012 5:20 PM
    Moderator
  • Woah, fromBuffer. That's rad. A hack, but rad. Is that even in the docs? IT IS! Who knew.

    Thanks a lot, again, for the help.

    S


    Check out my new C# 2010 All In One for Dummies book at Amazon!

    Friday, August 17, 2012 7:31 PM
  • You are welcome ;-)  Thanks for the chuckle Bill!

    Jeff Sanders (MSFT)

    Friday, August 17, 2012 7:32 PM
    Moderator
  • This code will give you a unique id for your device, but not one unique id.

    The problem with this code is that it will change if you change something with your computer.
    So if you plug in a USB mouse/keyboard it will create a different id.

    So if you're looking for a unique key you got it, but you can't use it to uniquely identify a computer.

    - Martin

    Wednesday, August 22, 2012 12:27 PM
  • That is a really good tip. As it is I am just using it as part of an authentication scheme, so it just has to be stable through the login process, but you make a very valid point.

    S


    Check out my new C# 2010 All In One for Dummies book at Amazon!

    Thursday, August 23, 2012 2:40 PM