public void Example_SecureStringHelper()
        {
            SecureString pin = this.ObtrainPin();

            SecureStringHelper.ExecuteWithSecureString(pin, Encoding.UTF8, pin =>
            {
                SetPinToDevice(pin);
            });
        }
 public static void Login(this ISession session, CKU userType, SecureString securePin)
 {
     if (securePin == null)
     {
         session.Login(userType, pin: null as byte[]);
     }
     else
     {
         SecureStringHelper.ExecuteWithSecureString(securePin, Encoding.UTF8, pin => session.Login(userType, pin));
     }
 }
        public void ExecuteWithSecureStringAction(string encodingname, string password)
        {
            SecureString secureString = this.Create(password);
            Encoding     encoding     = this.GetEncoding(encodingname);

            byte[] passwordBytes = password == null ? null : encoding.GetBytes(password);

            SecureStringHelper.ExecuteWithSecureString(secureString,
                                                       encoding,
                                                       array =>
            {
                CollectionAssert.AreEquivalent(passwordBytes, array);
            });
        }
        public void ExecuteWithSecureStringFunction(string encodingname, string password)
        {
            SecureString secureString = this.Create(password);
            Encoding     encoding     = this.GetEncoding(encodingname);

            byte[] passwordBytes = password == null ? null : encoding.GetBytes(password);

            int result = SecureStringHelper.ExecuteWithSecureString <int>(secureString,
                                                                          encoding,
                                                                          array =>
            {
                CollectionAssert.AreEquivalent(passwordBytes, array);
                return(13);
            });

            Assert.AreEqual(13, result);
        }
        public static byte[] Sign(this ISession session, IMechanism mechanism, IObjectHandle objectHandle, SecureString securePin, byte[] data)
        {
            if (mechanism == null)
            {
                throw new ArgumentNullException(nameof(mechanism));
            }
            if (objectHandle == null)
            {
                throw new ArgumentNullException(nameof(objectHandle));
            }
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }


            return(SecureStringHelper.ExecuteWithSecureString <byte[]>(securePin, Encoding.UTF8, pin => session.Sign(mechanism, objectHandle, pin, data)));
        }