【问题标题】:CoSign API: SAPI User Management (add edit delete) example?CoSign API:SAPI 用户管理(添加编辑删除)示例?
【发布时间】:2013-09-16 06:20:06
【问题描述】:

我的应用允许外部签名者签署文档。 ——不是雇员的签名者。我的应用程序将为他们创建一个 CoSign 数字证书。然后他们会签署文件,然后用户应该从系统中删除。我希望我的应用以编程方式创建/删除用户。

是否有用于 SAPI 用户管理 API 的 C# 示例?

【问题讨论】:

    标签: digital-signature cosign-api


    【解决方案1】:

    这是一个如何获取用户信息的 C# 示例

    namespace UMSample
    {
        class Program
        {
            private const string ADMIN_USER = "AdminUser";
            private const string ADMIN_PASS = "AdminPass";
    
            static public int AddUser(string uid)
            {
                SAPIUM sapium = new SAPIUMClass();
                SAPICrypt sapicrypt = new SAPICrypt();
                int rc;
    
                if ((rc = sapicrypt.Init()) != 0) return 1;
                if ((rc = sapium.Init()) != 0) return 1;
    
                UMSESHandle hSes = null;
                // Handle Acquire
                if ((rc = sapium.HandleAcquire(out hSes)) != 0) return 1;
    
                // Logon as Administrator
                if ((rc = sapium.Logon(hSes, ADMIN_USER, "", ADMIN_PASS)) != 0)
                {
                    sapium.HandleRelease(hSes);
                    return 1;
                }
    
                string UserCN = uid + " Test User";
                string UserEmail = uid+"@demo.com";
                string Pwd = "12345678";
    
                if ((rc = sapium.UserAdd(
                    hSes,
                    uid,
                    UserCN,
                    UserEmail,
                    Pwd,
                    1)) != 0)
                {
                    sapium.Logoff(hSes);
                    sapium.HandleRelease(hSes);
                    return 1;
                }
    
                /*----------------------------------*/
                // An example of how to get user info
                UserHandle uh;
                string s1, s2, s3, s4;
                int c1, c2, c3, mask = 0, updtime = 0;
                SAPI_UM_ENUM_USER_CERT_STATUS_TYPE certsts;
                SAPI_UM_ENUM_USER_LOGIN_STATUS loginstat;
                SAPI_UM_ENUM_USER_TYPE kind = SAPI_UM_ENUM_USER_TYPE.SAPI_UM_USER_TYPE_NONE;
                SAPI_UM_ENUM_USER_ENROLLMENT_STATUS enroll = SAPI_UM_ENUM_USER_ENROLLMENT_STATUS.SAPI_UM_NONE_USER_ENROLLMENT_STATUS;
                SAPI_UM_ENUM_USER_ENROLLMENT_REASON enrReason;
                SAPI_UM_ENUM_PENDING_REQUEST_STATUS_TYPE certrqsts;
    
                rc = sapium.UserGetByLoginName(hSes, uid, out uh);
                rc = sapium.UserInfoGetEx(hSes, uh, out s1, out s2, out s3, ref kind, ref mask, ref updtime, out s4,
                    out enroll, out enrReason, out loginstat, out c1, out c2, out c3, out certsts, out certrqsts);
                /*----------------------------------*/
    
                sapium.Logoff(hSes);
                sapium.HandleRelease(hSes);
    
                return 0;
            }
    
    
            static public int DelUser(string uid)
            {
                SAPIUM sapium = new SAPIUMClass();
                int rc;
    
                if ((rc = sapium.Init()) != 0) return 1;
    
                UMSESHandle hSes = null;
                if ((rc = sapium.HandleAcquire(out hSes)) != 0) return 1;
    
                if ((rc = sapium.Logon(hSes, ADMIN_USER, "", ADMIN_PASS)) != 0)
                {
                    sapium.HandleRelease(hSes);
                    return 1;
                }
    
                if ((rc = sapium.UserDelete(hSes, uid)) != 0)
                {
                    sapium.Logoff(hSes);
                    sapium.HandleRelease(hSes);
                    return 1;
                }
    
                sapium.Logoff(hSes);
                sapium.HandleRelease(hSes);
    
                return 0;
            }
    
            static void Main(string[] args)
            {
                int rc;
    
                for (int i = 0; i < 10; i++)
                {
                    string uid = "Test" + i;
                    rc = AddUser(uid);
                    if (rc != 0) {
                        Console.WriteLine ("Error adding user: " + uid);
                        return;
                    }
    
                    rc = DelUser(uid);                
                    if (rc != 0) {
                        Console.WriteLine ("Error deleting user: " + uid);
                        return;
                    }
                    Console.WriteLine("After handling user: " + uid);
                }
    
                Console.WriteLine("Press <Enter> to end");
                Console.ReadKey();
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-12-24
      • 2013-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-21
      • 2018-08-03
      • 1970-01-01
      • 2012-10-22
      相关资源
      最近更新 更多