BOOLEAN AnscAsn1PKCS10SignWithKeyParam ( ANSC_HANDLE hThisObject, PKI_KEY_TYPE keyType, ANSC_HANDLE hKeyPairHandle ) { PANSC_ASN1_CERTIFICATEREQUEST pThisObject = (PANSC_ASN1_CERTIFICATEREQUEST)hThisObject; PANSC_ASN1_PRIVATEKEYINFO pKeyInfo; BOOLEAN bResult; pKeyInfo = (PANSC_ASN1_PRIVATEKEYINFO) AnscAsn1CreatePrivateKeyInfoWithKey(NULL, keyType, hKeyPairHandle); if( pKeyInfo == NULL) { return FALSE; } bResult = pThisObject->SignWithPrivateKeyInfo ( pThisObject, pKeyInfo ); pKeyInfo->AsnFree(pKeyInfo); return bResult; }
/************************************************************************* * * This is the reverse api of above, with the given key type and KeyGenParams, * generate the private key info encoding; * *************************************************************************/ PUCHAR PKIUtilityGetPrivateKeyInfoEncoding ( ANSC_HANDLE hKeyGenParams, PKI_KEY_TYPE keyType, PULONG pLength ) { PANSC_ASN1_PRIVATEKEYINFO pKeyInfo; PUCHAR pEncoding; if( hKeyGenParams == NULL || pLength == NULL) { return NULL; } pKeyInfo = (PANSC_ASN1_PRIVATEKEYINFO) AnscAsn1CreatePrivateKeyInfo(NULL); if( pKeyInfo == NULL) { return NULL; } if( !pKeyInfo->InitKey(pKeyInfo, keyType, hKeyGenParams)) { pKeyInfo->AsnFree(pKeyInfo); return NULL; } pEncoding = pKeyInfo->GetEncodedData(pKeyInfo, pLength); pKeyInfo->AsnFree(pKeyInfo); return pEncoding; }
BOOLEAN AnscAsn1PKCS10InitKeyPair ( ANSC_HANDLE hThisObject, PKI_KEY_TYPE keyType, ANSC_HANDLE hKeyPairHandle ) { PANSC_ASN1_CERTIFICATEREQUEST pThisObject = (PANSC_ASN1_CERTIFICATEREQUEST)hThisObject; PANSC_ASN1_SUBJECTPUBLICKEYINFO pPublicKeyInfo; PANSC_ASN1_CERTIFICATIONREQUESTINFO pInfo; PANSC_ASN1_PRIVATEKEYINFO pKeyInfo; BOOLEAN bResult; if( pThisObject == NULL || hKeyPairHandle == NULL) { return FALSE; } pInfo = (PANSC_ASN1_CERTIFICATIONREQUESTINFO) pThisObject->GetCertificateRequestInfo(pThisObject); if( pInfo == NULL) { return FALSE; } pPublicKeyInfo = (PANSC_ASN1_SUBJECTPUBLICKEYINFO) pInfo->GetChildByIndex(pInfo,2); if( pPublicKeyInfo == NULL) { return FALSE; } if(!pPublicKeyInfo->GenerateKey ( pPublicKeyInfo, keyType, hKeyPairHandle )) { AnscTrace("Failed to set the public key.\n"); return FALSE; } pKeyInfo = (PANSC_ASN1_PRIVATEKEYINFO) AnscAsn1CreatePrivateKeyInfoWithKey(NULL, keyType,hKeyPairHandle); if( pKeyInfo == NULL) { return FALSE; } bResult = pThisObject->SignWithPrivateKeyInfo ( pThisObject, pKeyInfo ); pKeyInfo->AsnFree(pKeyInfo); return bResult; }