Adding an image to a VC with Microsoft Authenticator and Entra Verified ID
Claims in a VC can be both text and image.
There is not much information about VC images out there, but the docs. refer to:
“The uploaded photo for the user. The image type should be JPEG and the maximum size is 2MB. When presenting the photo claim to a verifier, the photo claim is in the UrlEncode(Base64Encode(photo)) format. To use the photo, the verifier application has to Base64Decode(UrlDecode(photo))”.
I created a VC for a “passport” that included a passport image.
I used this article for some hints.
The article shows the type of the image, which is:
"type": "image/jpg;base64url"
The JSON in the “passport” VC display file is then:
{
"claim": "vc.credentialSubject.Image",
"label": "Image",
"type": "image/jpg;base64url"
}
The JSON in the Postman file is then:
"Image": "_9j_4AAQSkZJRgABAgEAeAB4AAD_4QBaRXhpZgAATU0AKgAAAAgAAYdpAAQ.....hdj"
where you paste in the output of the code below.
The above article has some code that I adapted.
The code is:
using Microsoft.IdentityModel.Tokens;
using System;
using System.Drawing;
using System.IO;
class Program
{
static void Main()
{
try
{
// Provide the path to the image file
string imagePath = @"C:\...\Passport.jpg";
// Load the image from the file using a stream
using (FileStream stream = new FileStream(imagePath, FileMode.Open))
{
Image image = Image.FromStream(stream);
// Convert the image to Base64 encoded string
string base64Image = ConvertImageToBase64(image);
// Display the base64 encoded image
Console.WriteLine("Base64 Encoded Image:");
Console.WriteLine(base64Image);
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
I used this image from Wikimedia as my “passport” image:
I had to trim it because there is a limit on the size of the image.
If you look at the claims in the VC after you issue your “passport” VC, you’ll see:
All good!