2017-05-09 67 views
2

扔MissingMethodException當我運行下面的控制檯應用程序從窗口它工作AWS拉姆達(Linux內核版本 - 4.4.51-40.60.amzn1.x86_64)在Interop.Crypto.Pkcs12Parse

using System.Security.Cryptography.X509Certificates;  
public static void Main(string[] args) 
{ 
    Console.WriteLine("File exists: " + File.Exists("key.p12")); 
    var certificate = new X509Certificate2("key.p12", "notasecret"); 
    Console.WriteLine("Success"); 
    Console.ReadLine(); 
} 

但是當我試着AWS拉姆達其投擲的錯誤

.ctor: MissingMethodException 
at Interop.Crypto.Pkcs12Parse(SafePkcs12Handle p12, String pass, SafeEvpPKeyHandle& pkey, SafeX509Handle& cert, SafeX509StackHandle& ca) 
at Internal.Cryptography.Pal.OpenSslPkcs12Reader.Decrypt(String password) 
at Internal.Cryptography.Pal.PkcsFormatReader.TryReadPkcs12(OpenSslPkcs12Reader pfx, String password, Boolean single, ICertificatePal& readPal, List`1& readCerts) 
at Internal.Cryptography.Pal.PkcsFormatReader.TryReadPkcs12(SafeBioHandle bio, String password, Boolean single, ICertificatePal& readPal, List`1& readCerts) 
at Internal.Cryptography.Pal.CertificatePal.FromBio(SafeBioHandle bio, String password) 
at Internal.Cryptography.Pal.CertificatePal.FromFile(String fileName, String password, X509KeyStorageFlags keyStorageFlags) 
at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags) 
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password) 
at test_openssl_lambda.Functions.TriggerSync() in /tmp/src818283224/src/test-openssl-lambda/test_openssl_lambda/Function.cs:line 21 
at lambda_method(Closure , Stream , Stream , ContextInfo) 

下面是我project.json

{ 
    "version": "1.0.0-*", 
    "buildOptions": { 
    "emitEntryPoint": false 
    }, 

    "dependencies": { 
    "Microsoft.NETCore.App": { 
     "type": "platform", 
     "version": "1.0.0" 
    }, 

    "Amazon.Lambda.Core": "1.0.0", 
    "Amazon.Lambda.APIGatewayEvents": "1.1.0", 
    "Amazon.Lambda.Serialization.Json": "1.1.0", 
    "Amazon.Lambda.Tools": { 
     "type": "build", 
     "version": "1.5.0" 
    }, 

    "System.Security.Cryptography.X509Certificates": "4.3.0" 
    }, 

    "tools": { 
    "Amazon.Lambda.Tools": "1.5.0" 
    }, 

    "frameworks": { 
    "netcoreapp1.0": { 
     "imports": "dnxcore50" 
    } 
    } 
} 

並呼籲Function.cs(這是上面的控制檯應用程序相同)

using System.Security.Cryptography.X509Certificates; 
using Amazon.Lambda.Core; 

[LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] 
public void Trigger() 
{ 
    Console.WriteLine("File exists: " + File.Exists("Key.p12")); 
    var certificate = new X509Certificate2("Key.p12", "notasecret"); 
    Console.WriteLine("Success"); 
} 

它拋出異常,因爲它無法做到的DllImport System.Security.Cryptography.Native.OpenSsl在AWS LAMBDA環境(Linux內核版本 - 4.4 .51-40.60.amzn1.x86_64) 有人可以幫我解決這個問題嗎?即幫助我在AWS Lambda中安裝System.Security.Cryptography.Native.OpenSsl?

回答