CryptoAPI - CryptoSetProvParam

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ekpai
    New Member
    • Oct 2007
    • 1

    #1

    CryptoAPI - CryptoSetProvParam

    Hi everyone,

    I am quite newbie in security development. So sorry in advance if u feel i am asking something obvious. I am trying to login into a USB token
    from Aladdin. I am using the below code but I am getting all the time an error in the CryptSetProvPar am. I do not know why i cannot login into
    the token. What is wrong in my code?

    The vendor doc says that pbData should be an ASCII null terminating string so I ave also tried with passwd "1234567890 \0"

    Also, is there a way to change the password?

    Thanks a lot in advance,
    Diego

    byte[] bytes = Encoding.ASCII. GetBytes("12345 67890");
    if (PAOLibToken.Cr yptAcquireConte xt(ref cspHandle, null, provName, PROV_RSA_FULL, CRYPT_VERIFYCON TEXT))
    {
    if (PAOLibToken.Cr yptSetProvParam (cspHandle, PP_KEYEXCHANGE_ PIN, bytes, 0) == true)
    {
    Console.WriteLi ne("OK");
    }
    }

    ///The DllImport Section
    [DllImport("adva pi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    [return: MarshalAs(Unman agedType.Bool)]
    static extern bool CryptAcquireCon text(ref IntPtr hProv, string pszContainer,
    string pszProvider, uint dwProvType, uint dwFlags);

    [DllImport("adva pi32.dll", SetLastError = true)]
    public static extern bool CryptSetProvPar am(IntPtr hProv, uint dwParam, [In] byte[] pbData, uint dwFlags);
Working...