第二十章:安全性

1. MD5加密

通常我们Login的时候使用的密码需要加密(加密和Hash的区别),并且是不可逆的加密,这个时候可以使用MD5。

MD5 is an algorithm that is used to verify data integrity through the creation of a 128-bit message digest from data input (which may be a message of any length) that is claimed to be as unique to that specific data as a fingerprint is to the specific individual.

在Java中有现成的方法进行Password加密。在ionic中我们可以使用ng-md5来实现。 

2. RSA加密

RSA is an algorithm used by modern computers to encrypt and decrypt messages. It is an asymmetric cryptographic algorithm. Asymmetric means that there are two different keys. This is also called public key cryptography, because one of them can be given to everyone. The other key must be kept private.

ionic中RSA加密、解密

3. 使用HTTPS

有了加密或者hash算法,但是想要在网络上安全地进行数据传输,防止数据被窃听、防止通讯方被篡改、保证数据完整性,我们就需要使用HTTPS来进行通信。

HTTPS并不是一个新的协议,是在HTTP协议之上使用了SSL(Secure Socket Layer)协议来保证安全传输。

SSL (Secure Sockets Layer) is the standard security technology for establishing an encrypted link between a web server and a browser. This link ensures that all data passed between the web server and browsers remain private and integral.

3.1 使用ionic本身的$http就可以,不用使用Cordova-HTTP

3.2 Web Service支持HTTPS:在iis上面配置ssl

3.3 enable TLS 1.2,因为ios 9的ATS机制有变化。

3.4 在Windows平台下的Chrome中安装证书,现在可以在Chrome浏览器中成功运行使用HTTPS服务的ionic app。

3.5 忽略SSL证书错误即不需要任何证书也可以进行HTTPS访问,这样就失去了HTTPS的意义,但至少在debug模式下可以使用。

<key>NSAppTransportSecurity</key>
<dict>
  <!--Include to allow all connections (DANGER)-->
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>

 3.6 因为暂时没有CA认证的证书,所以没有办法验证release环境下的HTTPS的调用。

参考资料:

原文地址:https://www.cnblogs.com/allanli/p/ionic_security.html