语言

DevicePolicyManager.GenerateKeyPair 方法

定义

重载

名称 说明
GenerateKeyPair(ComponentName, String, KeyGenParameterSpec, IdAttestationFlags)

可以通过以下方法调用此 API 以生成新的私钥/公钥对:ul<li Device owner/li li><>Profile owner<>/li<><li Delegated certificate installer>/li li Credential management app/<><li><li>An app< that holds the > permission</li>android.Manifest.permission#MANAGE_DEVICE_POLICY_CERTIFICATES/ul<><>如果设备支持通过安全硬件生成密钥,此方法可用于在 KeyChain 中创建从未离开安全硬件的密钥。

GenerateKeyPair(String, KeyGenParameterSpec, IdAttestationFlags, KeyChainManagerKeyPairScope)

生成具有指定作用域的新私钥/公钥对。

GenerateKeyPair(ComponentName, String, KeyGenParameterSpec, IdAttestationFlags)

可以通过以下方法调用此 API 以生成新的私钥/公钥对:ul<li Device owner/li li><>Profile owner<>/li<><li Delegated certificate installer>/li li Credential management app/<><li><li>An app< that holds the > permission</li>android.Manifest.permission#MANAGE_DEVICE_POLICY_CERTIFICATES/ul<><>如果设备支持通过安全硬件生成密钥,此方法可用于在 KeyChain 中创建从未离开安全硬件的密钥。

[Android.Runtime.Register("generateKeyPair", "(Landroid/content/ComponentName;Ljava/lang/String;Landroid/security/keystore/KeyGenParameterSpec;I)Landroid/security/AttestedKeyPair;", "GetGenerateKeyPair_Landroid_content_ComponentName_Ljava_lang_String_Landroid_security_keystore_KeyGenParameterSpec_IHandler", ApiSince=28)]
[Android.Runtime.RequiresPermission("android.permission.MANAGE_DEVICE_POLICY_CERTIFICATES")]
public virtual Android.Security.AttestedKeyPair? GenerateKeyPair(Android.Content.ComponentName? admin, string algorithm, Android.Security.Keystore.KeyGenParameterSpec keySpec, Android.App.Admin.IdAttestationFlags idAttestationFlags);
[<Android.Runtime.Register("generateKeyPair", "(Landroid/content/ComponentName;Ljava/lang/String;Landroid/security/keystore/KeyGenParameterSpec;I)Landroid/security/AttestedKeyPair;", "GetGenerateKeyPair_Landroid_content_ComponentName_Ljava_lang_String_Landroid_security_keystore_KeyGenParameterSpec_IHandler", ApiSince=28)>]
[<Android.Runtime.RequiresPermission("android.permission.MANAGE_DEVICE_POLICY_CERTIFICATES")>]
abstract member GenerateKeyPair : Android.Content.ComponentName * string * Android.Security.Keystore.KeyGenParameterSpec * Android.App.Admin.IdAttestationFlags -> Android.Security.AttestedKeyPair
override this.GenerateKeyPair : Android.Content.ComponentName * string * Android.Security.Keystore.KeyGenParameterSpec * Android.App.Admin.IdAttestationFlags -> Android.Security.AttestedKeyPair

参数

admin
ComponentName

此请求与哪个 DeviceAdminReceiver 请求相关联,或者 null 调用方不是设备管理员。

algorithm
String

密钥生成算法,请参阅 java.security.KeyPairGenerator。

keySpec
KeyGenParameterSpec

要生成的密钥的规范,请参阅 java.security.KeyPairGenerator。

idAttestationFlags
IdAttestationFlags

应包含在证明记录(ID_TYPE_BASE_INFOID_TYPE_SERIALID_TYPE_IMEI和ID_TYPE_MEID)中的标识符的位掩码,以及ID_TYPE_INDIVIDUAL_ATTESTATION是否应使用单个证明证书对证明记录进行签名。 <如果在证明记录中不需要设备标识,并且应使用批处理证明证书,则应传入 p>0 。 <p> 如果指定了任何标志,则必须将证明质询包含在其中 keySpec。

返回

如果密钥生成成功,则为非 null AttestedKeyPair ,否则为 null。

特性

注解

可以通过以下方法调用此 API 以生成新的私钥/公钥对:ul<li Device owner/li li><>Profile owner<>/li<><li Delegated certificate installer>/li li Credential management app/<><li><li>An app< that holds the > permission</li>android.Manifest.permission#MANAGE_DEVICE_POLICY_CERTIFICATES/ul<><>如果设备支持通过安全硬件生成密钥,此方法可用于在 KeyChain 中创建从未离开安全硬件的密钥。 对密钥的访问与在中 #installKeyPair控制的方式相同。

从 Android android.os.Build.VERSION_CODES#S中,凭据管理应用可以调用此 API。 如果凭据管理应用调用,则 componentName 必须为 null。 请注意,在非托管设备上只能有凭据管理应用。

由于此方法可能需要几秒钟才能完成,因此只能从工作线程调用此方法。 此方法从主线程调用时返回 null 。

此方法不是线程安全的,同时从多个线程调用此方法将导致未定义的行为。 如果在调用处于正在进行的状态时调用线程中断,最终将终止并返回 null。

注意:如果提供的 alias 是现有别名,则会撤销所有以前授予应用访问与此别名关联的密钥和证书的权限。

证明:若要启用证明,请通过设置keySpec证明质询KeyGenParameterSpec.Builder#setAttestationChallenge。 通过向参数指定标志 idAttestationFlags ,可以请求将设备的唯一标识包含在证明记录中。

特定标识符可以包含在证明记录中,单个证明证书可用于对证明记录进行签名。 若要了解设备是否支持这些功能,请参阅和 #isDeviceIdAttestationSupported()。#isUniqueDeviceAttestationSupported()

设备所有者、配置文件所有者、其委托的证书安装程序和凭据管理应用可用于 #ID_TYPE_BASE_INFO 请求在证明记录中包含常规设备信息,包括制造商、型号、品牌、设备和产品。 只有设备所有者、组织拥有的设备或关联用户的配置文件所有者及其委托的证书安装程序才能使用 #ID_TYPE_SERIAL, #ID_TYPE_IMEI 并 #ID_TYPE_MEID 请求唯一的设备标识符进行证明(序列号、IMEI 和 MEID 对应),如果设备支持(请参阅 #isDeviceIdAttestationSupported())。 此外,设备所有者、组织拥有的设备上的配置文件所有者及其委托的证书安装程序还可以通过指定 #ID_TYPE_INDIVIDUAL_ATTESTATION 标志(如果设备支持) #isUniqueDeviceAttestationSupported()来请求使用单个证明证书进行签名的证明记录。

如果已设置,#ID_TYPE_SERIAL#ID_TYPE_IMEI则#ID_TYPE_MEID隐式假定#ID_TYPE_BASE_INFO也已设置。

只有在 StrongBox 中完成密钥生成时,才能请求使用 #ID_TYPE_INDIVIDUAL_ATTESTATION 证明。

Java文档android.app.admin.DevicePolicyManager.generateKeyPair(android.content.ComponentName, java.lang.String, android.security.keystore.KeyGenParameterSpec, int)。

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于

GenerateKeyPair(String, KeyGenParameterSpec, IdAttestationFlags, KeyChainManagerKeyPairScope)

生成具有指定作用域的新私钥/公钥对。

[Android.Runtime.Register("generateKeyPair", "(Ljava/lang/String;Landroid/security/keystore/KeyGenParameterSpec;II)Landroid/security/AttestedKeyPair;", "GetGenerateKeyPair_Ljava_lang_String_Landroid_security_keystore_KeyGenParameterSpec_IIHandler", ApiSince=37)]
[Android.Runtime.RequiresPermission("android.permission.MANAGE_DEVICE_POLICY_CERTIFICATES")]
public virtual Android.Security.AttestedKeyPair GenerateKeyPair(string algorithm, Android.Security.Keystore.KeyGenParameterSpec keySpec, Android.App.Admin.IdAttestationFlags idAttestationFlags, Android.Security.KeyChainManagerKeyPairScope scope);
[<Android.Runtime.Register("generateKeyPair", "(Ljava/lang/String;Landroid/security/keystore/KeyGenParameterSpec;II)Landroid/security/AttestedKeyPair;", "GetGenerateKeyPair_Ljava_lang_String_Landroid_security_keystore_KeyGenParameterSpec_IIHandler", ApiSince=37)>]
[<Android.Runtime.RequiresPermission("android.permission.MANAGE_DEVICE_POLICY_CERTIFICATES")>]
abstract member GenerateKeyPair : string * Android.Security.Keystore.KeyGenParameterSpec * Android.App.Admin.IdAttestationFlags * Android.Security.KeyChainManagerKeyPairScope -> Android.Security.AttestedKeyPair
override this.GenerateKeyPair : string * Android.Security.Keystore.KeyGenParameterSpec * Android.App.Admin.IdAttestationFlags * Android.Security.KeyChainManagerKeyPairScope -> Android.Security.AttestedKeyPair

参数

algorithm
String

密钥生成算法,请参阅 java.security.KeyPairGenerator。

keySpec
KeyGenParameterSpec

要生成的密钥的规范,请参阅 java.security.KeyPairGenerator。

idAttestationFlags
IdAttestationFlags

应包含在证明记录中的标识符的位掩码。 有关详细信息,请参阅基本方法。

scope
KeyChainManagerKeyPairScope

键对的范围: KeyChainManager#KEYPAIR_SCOPE_USER 或 KeyChainManager#KEYPAIR_SCOPE_DEVICE。

返回

非 null AttestedKeyPair。

特性

注解

生成具有指定作用域的新私钥/公钥对。

此方法扩展 generateKeyPair(ComponentName,String,KeyGenParameterSpec,int),添加范围参数以确定密钥对是用户特定的还是设备范围的。

有关常规功能、权限、调用方类型、证明、安全硬件使用情况和异常的完整详细信息,请参阅 generateKeyPair(ComponentName、String、KeyGenParameterSpec、int)的文档。

此重载的主要差异:

必须提供 scope 参数来定义密钥的可见性。

使用KeyChainManager.KEYPAIR_SCOPE_DEVICE:密钥对可在设备上的所有关联用户中访问。 请参阅 isAffiliatedUser()。 调用方必须在关联用户中运行才能使用此范围。 不允许凭据管理应用使用此范围。

使用 KeyChainManager.KEYPAIR_SCOPE_USER:密钥对是呼叫用户的专用密钥对。 这反映了 base generateKeyPair 方法的行为。

注意:与基本方法一样,这可能需要几秒钟时间,不应在主线程上调用。 它不是线程安全的。

Android 参考。android.app.admin.DevicePolicyManager.generateKeyPair

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于