我有一个位于Tomcat的属性文件和一个位于src/test/resources中的测试属性文件.
目前我有以下设置.我的属性文件加载到我的XML文件 config.xml中
<?xml version="1.0" encoding="UTF-8"?>
<!-- Repository and Service layers -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<!-- ========================= RESOURCE DEFINITIONS ========================= -->
<context:component-scan base-package="be.omniatravel.service" />
<context:property-placeholder
location="file:${catalina.base}/conf/omniatravel.properties"
ignore-unresolvable="true" />
<tx:annotation-driven />
</beans>
Run Code Online (Sandbox Code Playgroud)
测试-config.xml中
<?xml version="1.0" encoding="UTF-8"?>
<!-- Repository and Service layers -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<!-- ========================= RESOURCE DEFINITIONS ========================= -->
<context:component-scan base-package="be.omniatravel.service" /> …Run Code Online (Sandbox Code Playgroud) 我必须将我的哈希密码转换为字符串.
这是我的代码.
<?php namespace App\Http\Controllers;
use DB;
use Auth;
use Input;
use Session;
use Route;
use Crypt;
use Redirect;
use Illuminate\Http\Request;
use Illuminate\Http\Dispatcher;
$userdata = array(
'email' => $email,
'password' => Crypt::decrypt($password)
);
Run Code Online (Sandbox Code Playgroud)
当我使用Crypt :: decrypt我得到错误.错误-
DecryptException in BaseEncrypter.php line 45:
The payload is invalid.
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议我怎么做?
谢谢.
我正在尝试为将存储客户机密数据的用户构建一个平台.上下文非常简单:法国法律禁止我访问我的用户将存储的数据(例如患者的医疗记录).
因此,当用户提交将存储在数据库中的数据时,他应该是唯一可以访问该信息的人.例如,用密码加密它.这样,如果我登录到mysql,我只会看到加密的废话并且没有可读数据.
我的哲学可能是错的,就是通过这样做来学习.希望你们对我的方法感到满意.
问题是:我不知道从哪里开始,如何做到这一点......实际上甚至没有在谷歌搜索什么.我甚至试图在codecanyon.net上找到适合的东西,并且不喜欢任何相关的脚本.
提前致谢 :) !
PS:我实际上会遇到与文件相同的问题(jpg,word,pdf,xls ......应该足够用户).但这是另一个故事.
我正在尝试使用谷歌的https://code.google.com/p/crypto-js/#AES在JavaScript中加密某些内容,就像示例一样.问题是,我试图用Java解密它的结果是不同的.我可以看到的唯一区别是填充(CryptoJs使用Pkcs7而java使用Pkcs5),读了一下我意识到Pkcs7和Pkcs5基本相同.
以下是我在Javascript中进行加密的代码示例:
var crypto = require('./aes.js');
var login = 'ABCD';
var key = crypto.CryptoJS.enc.Hex.parse('0123456789012345');
var ive = crypto.CryptoJS.enc.Hex.parse('0123456789012345');
var encrypted = crypto.CryptoJS.AES.encrypt(login, key, {iv: ive});
console.log('encrypted msg = ' + encrypted)
Run Code Online (Sandbox Code Playgroud)
这是我用Java解密它的代码:
public String decrypt(byte[] cipherText) throws Exception {
String psk = "0123456789012345";
String iv = "0123456789012345";
try {
String encryptionKey = psk;
final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "SunJCE");
final SecretKeySpec key = new SecretKeySpec(encryptionKey.getBytes(UTF8), "AES");
cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv.getBytes(UTF8)));
return new String(cipher.doFinal(cipherText), UTF8);
} catch (BadPaddingException | …Run Code Online (Sandbox Code Playgroud) 我在Linux系统上使用keytab文件来验证使用kerberos的服务.我想知道这个密码是如何实际存储到该keytab文件中的.正如我们在/ etc/passwd中所知,密码是在应用单向散列方法后存储的 - 因此无法从中计算明文密码.
但是如何在keytab文件中完成?使用keytab的进程必须知道密码才能验证用户?!它是否使用主密码加密,因此可以解密?
我用它来创建一个keytab文件:
$ ktutil
ktutil: addent -password -p my_user@MYREALM -k 1 -e rc4-hmac
Password for my_user@MYREALM:
ktutil: wkt my_user.keytab
ktutil: quit
Run Code Online (Sandbox Code Playgroud)
使用该keytab,我可以在不输入密码的情况下获得krbtgt.创建密钥表时,无法与AD/KDC进行通信(因此没有可用于签名的共享密钥或其他内容).
那么如何将密码加密到keytab中?如果它不是哈希算法 - 是否可以解密它?
我的代码有问题,当我加密数据时,例如,在这种情况下,我用接收者的公钥加密的simmetric密钥,然后保存到文本文件,当我读取该文本文件并尝试解密时,使用接收者的私钥,我得到一个不同的密钥,因此我不能用它来解密加密的消息.
发件人的代码:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.security.KeyStore;
import java.security.MessageDigest;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
class Sender{
public static void main(String[] args) {
//infile.txt
File inFile = new File(args[0]);
//outfile.txt
File outFile = new File(args[1]);
//mykeystore.jks
File keyStoreFile = new File(args[2]);
//mykeystore info
String alias = args[3];
String password = args[4];
String storepass = args[5];
//receptor certificate
String receptorCert = args[6];
try {
//Read plain …Run Code Online (Sandbox Code Playgroud) 我想采用JSON字符串并对其进行加密/散列/编码,以便我可以将其放入URL中,以便它类似于下面所示的内容:
var stringToEncode = JSON.stringify({foo: 'baz', bar: [1,2,3,4,5], baz: {fizzle: 'buzz'}});
Run Code Online (Sandbox Code Playgroud)
'www.myrandomurl.com/someurl/123fas234asf1543rasfsafda'
然后我想采用加密/散列/编码的字符串,并将其解码回原始的JSON字符串,以便我可以使用它绑定到单页AngularJS应用程序上的各种元素.
JSON字符串的内容不敏感,因此不需要安全性或复杂的散列.唯一的条件是它需要是一个"URL/URI'安全'"字符串,为了虚荣目的进行哈希处理,如上所示.
我对加密/编码的知识有限,但是我想过简单地将字符串编码为Base64并再次解码.
这是最好的方法吗?如果不是,有什么更好的方法?
我理解在客户端想要将数据安全地发送到服务器的上下文中的非对称加密的概念.服务器将公钥发送到用于加密数据的客户端.服务器使用它的私钥解密消息.在这种情况下,一切都有意义,因为私钥只能由服务器访问.
但是,如果客户想要安全地接收数据呢?相同的概念可以适用于相反的方向(前端共享公钥并拥有私钥),除了私钥可供任何人使用,因为javascript中的源代码在Web浏览器中可用,它会失败加密的目的......
当然有一个解决方案.在搜索时我没有找到我的问题的明确答案,尽管许多人提到了HTTPS.我也想知道为什么以及如何运作以及我的知识存在缺陷.
客户端如何安全地从服务器接收数据?
javascript encryption frontend encryption-asymmetric public-key-encryption
通过阅读我附带的要点,最容易理解这个问题:https://gist.github.com/KazW/e77e5c7603d7700d86c1
我在Ruby中有一个简单的加密/解密函数.每次运行加密函数时,都会使用创建新的初始化向量OpenSSL::Random.random_bytes(12).当我尝试在Elixir中使用相同的步骤时:crypto.strong_rand_bytes(12),它会生成一个可用于加密的IV,但会导致解密失败.
更奇怪的是,如果我使用在Ruby中生成的IV,并将其用于Elixir中的加密.当传递密文以在Elixir中解密时,解密函数返回明文而没有错误.我研究了使用中的算法,IV应该是随机字节,重要的因素是它中的字节数(12).
我最初的想法是,也许我正在调用错误的OpenSSL方法来生成IV.但是,我无法找到任何关于正确方法的信息.
我有一个API,我安装了下一个gem
gem 'bcrypt'
Run Code Online (Sandbox Code Playgroud)
进入我的用户模型我具体说:
has_secure_password
Run Code Online (Sandbox Code Playgroud)
我的数据库有一个名称字段
password_digest
Run Code Online (Sandbox Code Playgroud)
并且当运行播种器时,密码是加密的,但是当尝试从我的方法创建一个新用户时,密码是正常的,这是我创建新用户的方法
def self.from_auth(data)
User.where(email: data[:email]).first_or_create do |user|
user.email = data[:info][:email]
user.name = data[:info][:name]
user.provider = data[:info][:provider]
user.uid = data[:info][:uid]
user.password_digest = data[:info][:password]
end
end
Run Code Online (Sandbox Code Playgroud)
谢谢 :)