local lcHash as Character, lcPublicKey as Character, ; lcCAF as Character, lcData as Character, ; loHash as Object set Safety off clear lcCAF = fileToStr('D:\Factura Electrónica\Prueba.xml') public gcCAF gcCAF = lcCAF declare long RSA_CheckKey in 'diCrPKI.dll' string strKeyString, ; long nOptions declare long HASH_HexFromBytes in diCrPKI.dll string @ sHexDigest, ; long nLenHex, ; string stringToHash, ; long lenStringToHash, ; long nOptions declare long RSA_ReadPrivateKeyInfo in "diCrPKI.dll" string @ , ; long nKeyMaxLen, ; string strKeyFileName, ; long nOptions declare long RSA_RawPublic in 'diCrPKI.dll' string @ abData, ; integer dataLen, ; string strPublicKey, ; integer options declare long RSA_RawPrivate in 'diCrPKI.dll' string @ abData, ; integer dataLen, ; string strPrivateKey, ; integer options declare long RSA_EncodeMsg in "diCrPKI.dll" string @ abOutput, ; long nOutputLen, ; string @ abMessage, ; long nMsgLen, ; long nOptions declare long RSA_DecodeMsg in "diCrPKI.dll" string @ abOutput, ; long nOutputLen, ; string @ abMessage, ; long nMsgLen, ; long nOptions lcPublicKey = strExtract(lcCAF, '<RSAPUBK>', '</RSAPUBK>') lcPrivateKey = strExtract(lcCAF, '<RSASK>', '</RSASK>') lcData = strExtract(lcCAF, '<DA>', '</DA>') lcSignature = strExtract(lcCAF, '"SHA1withRSA">', '</FRMA>') public mi1 mi1 = lcSignature *-- Get the hash of the data with cryptPack loHash = newObject('cryptPak', 'd:\3rdparty\cryptpak\cryptpak.vcx') local lcHashCrypt lcHashCrypt = strconv(loHash.SHA1(lcData), 15) ? 'cryptPak', lcHashCrypt public mi2 mi2 = lcHashCrypt *-- Get the hash of the data with cryptPKI local lcHash as Character, lnKeyLen as Integer lcHash = space(40) lnKeyLen = HASH_HexFromBytes(@lcHash, 40, lcData, len(lcData), 0) ? 'cryptPKI', lnKeyLen, upper(lcHash), lnKeyLen ? lcHashCrypt == upper(lcHash) *-- Get public key Declare long RSA_ReadPublicKey in "diCrPKI.dll" string @ , ; long nKeyMaxLen, ; string strKeyFileName, ; long nOptions strToFile(lcPublicKey, 'temp.key') lcKey = '' lnLen = RSA_ReadPublicKey("", 0, 'temp.key', 0) if lnLen > 0 lcKey = space(lnLen) mi = RSA_ReadPublicKey(@lcKey, lnLen, 'temp.key', 0) endIf ? 'ReadPublicKey', mi, lcKey, lnLen *-- Check the key ? 'Check key', RSA_CheckKey(lcKey, 0) *-- Get private key strToFile(lcPrivateKey, 'temp.key') lcPrivateInternalKey = '' lnLen = RSA_ReadPrivateKeyInfo("", 0, 'temp.key', 0) if lnLen > 0 lcPrivateInternalKey = space(lnLen) mi = RSA_ReadPrivateKeyInfo(@lcPrivateInternalKey, lnLen, 'temp.key', 0) endIf ? 'ReadPrivateKey', mi, lcPrivateInternalKey, lnLen lcMensaje = 'hola' local lcResult lcEncoded = space(64) ? 'RSA_EncodeMsg', RSA_EncodeMsg(@lcEncoded, 64, @lcMensaje, 4, 0), lcEncoded lResult = RSA_RawPublic(@lcEncoded, len(lcEncoded), lcKey, 0) ? 'RSA_RawPublic', lResult, lcEncoded lResult = RSA_RawPrivate(@lcEncoded, len(lcEncoded), lcPrivateInternalKey, 0) ? 'RSA_RawPrivate', lResult, lcEncoded local lnOriginalSize lnOriginalSize = RSA_DecodeMsg(0, 0, @lcEncoded, len(lcEncoded), 0) lcDecoded = space(lnOriginalSize) ? 'RSA_DecodeMsg', RSA_DecodeMsg(@lcDecoded, lnOriginalSize, @lcEncoded, len(lcEncoded), 0), lcDecoded *-- Decrypt signature lcSignature = strconv(strExtract(lcCAF, '"SHA1withRSA">', '</FRMA>'), 14) lResult = RSA_RawPublic(@lcSignature, len(lcSignature), lcKey, 0) ? 'Signature in PKCS#1: ', lResult, lcSignature lnOriginalSize = RSA_DecodeMsg(0, 0, lcSignature, len(lcSignature), 0) if lnOriginalSize > 0 lcDecoded = space(lnOriginalSize) ? 'Signature decoded: ', RSA_DecodeMsg(@lcDecoded, lnOriginalSize, @lcSignature, len(lcSignature), 0), lcDecoded else ? 'Fail: ', lnOriginalSize endIf ************************************************************************************ ************************************************************************************ loHash = .NULL. loHashMethod = .NULL. set Safety on return>Hola a todos por un lado les dire que ando algo desesperado ya que llevo bastantes dias tratando de encriptar una cadena con RSA pero por desgracia no e podido lograrlo e encontrado ejemplos de todo tipo pero de otro lenguajes menos del querido zorrito y es que aqui en mexico han metido lo que se llama facturación electronica y ahi nos dan un certificado con una llave pero no e logrado hacer este paso no se si alguien me pueda orientar de como puedo lograrlo ya que mis jefes me quieren colgar y por mas que busco no e encontrado nada sin mas me despido