2011-11-22 85 views
1

我有WCF服務,即獲取並返回JSON數據。以及調用此服務的Android移動應用程序。WCF服務(JSON)和Android客戶端 - 信息安全

  • 如果可能,我如何加密這兩者之間的消息?
  • 如果沒有,如何做自定義加密?

編輯:

這裏是服務器端和客戶端的附加信息。

服務看起來未來:

服務接口

<ServiceContract()> 
Public Interface ITest 

    <OperationContract()> 
    <WebInvoke(Method:="POST", RequestFormat:=WebMessageFormat.Json, ResponseFormat:=WebMessageFormat.Json, BodyStyle:=WebMessageBodyStyle.WrappedRequest)> 
    Function Test(header As RequestHeader, body As TestRequestResponse) As Boolean 

End Interface 

服務代碼

<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> 
<ServiceBehavior(ConcurrencyMode:=ConcurrencyMode.Multiple, InstanceContextMode:=InstanceContextMode.Single)> 
Public Class TestService 
    Implements ITest 

    Public Function Test(header As RequestHeader, body As TestRequestResponse) As Boolean Implements ITest.Test 

     Return True 

    End Function 

End Class 

的Web.Config

<system.serviceModel> 
    <services> 
     <service behaviorConfiguration="RMWS.TestBehavior" name="RMWS.TestService"> 
      <endpoint address="Test" binding="webHttpBinding" behaviorConfiguration="WebBehavior" bindingConfiguration="WebBinding" contract="RMWS.ITest" /> 
     </service> 
    </services> 
    <bindings> 
     <webHttpBinding> 
     <binding name="WebBinding"/> 
     </webHttpBinding> 
    </bindings> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="WebBehavior"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior name="RMWS.TestBehavior"> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="false" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
</system.serviceModel> 

客戶端調用

客戶端調用目前從JavaScript製成僅可用於測試。將來客戶端將是Android應用程序,但總體思路是一樣的。

$.ajax({ 
    type: "POST", 
    url: "http://localhost/RMWS/TestService.svc/Test/Test", 
    contentType: "application/json", 
    dataType: "json", 
    data: JSON.stringify(somedata), 
    success: function (data) 
    { 
     ... 
    }, 
    error: function (httpRequest, textStatus, errorThrown) 
    { 
     alert(textStatus + ": " + errorThrown); 
    } 
}); 

編輯2:

我知道它可以很容易地使用SSL來完成。但是在我的公司認爲它對於性能和流量來說太昂貴了,所以他們不想使用SSL,而是使用其他一些加密技術。如果可能的話,只有請求可能被編碼,因爲響應不包含任何敏感信息。

編輯3:

除了約瑟夫的回答沒有其他意見?

+0

請更新您的問題,給我們的更多信息:您的客戶是如何連接到您的服務?你嘗試過什麼,等 –

+0

@Terry Donaghe:見問題的更新,請 – Kamarey

回答

1

SSL是最好的選擇,如果你想繼續使用JSON,你可以混淆JSON但將不再是JSON和將是愚蠢的,仍然是那些誰是真正感興趣的訪問。

你最好的辦法是到設備發送二進制,您可以加密使用PGP但問題你將不得不被存儲在一個Android應用程序,這本身也不是很安全的私鑰。

SSL是最安全的賭注。

+0

你知道有什麼區別在SSL VS其他加密流量/性能?這種差異是否更難實施SSL以外的東西? – Kamarey

+0

區別在於你的時間值多少錢。 SSL是一種已知的解決方案,而您將不得不重寫客戶端服務器,這是一個未知數量。 –

+0

同意你的意見。但要知道它是否值得,我想了解使用SSL加密等其他方法需要多少時間/精力。我不是服務安全方面的大師,所以想知道這是否是一件事,可以在1小時內完成,或者需要數週的工作。 – Kamarey