How can I get Data obj from AES.GCM.Nonce - swift

516 Views Asked by At

I am using AES.GCM.seal(textData, using: retrievedKey), to encrypt some information. I need access to encrypted.nonce as a Data. How do I achieve this?

1

There are 1 best solutions below

0
On

The Data type has an initializer that accepts any type that conforms to the Sequence protocol. You can use it to initialize a Data from AES.GCM.Nonce because the definition of AES.GCM.Nonce shows that it conforms to the Sequence protocol:

public struct Nonce : ContiguousBytes, Sequence

So you can easily do this:

let nonceData = Data(encrypted.nonce)

and you will get a Data from your AES.GCM.Nonce.