解密返回奇怪的字符 [英] Decryption returning strange characters
本文介绍了解密返回奇怪的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经创建了一个解密脚本,虽然它返回一个带有奇怪符号的垃圾字符串,但它不会抛出任何错误。
加密字符串示例:fff:T3UZSkX4vsJxnWEaIMWK3w ==
解码后:ㅎヨ5pチㅎミㅎワワㅎ`ㅎ,Chㅈㄴ/
我用来解密的脚本部分是,
I have created an decryption script, and it complies without throwing any errors although it returns a junk string with strange symbols.
An example of encrypted string: fff: T3UZSkX4vsJxnWEaIMWK3w==
When decoded: ᄒヨ5pチᄒミᄒワᄒᆰ`ᄒᄆ,Chホᄌᄂ
The part of script I am using to decrypt is,
#Call decryption method
item = decryptDatabag(project, domain)
puts(item["chef_password"])
puts(item["Password"])
end
def decryptDatabag(project, domain)
#Read in the password for Artifactory
contents = File.read("\\\\############\\ChefEncryptedKeys\\secretpassword.txt")
#Get the secret file from Artifactory
system("wget -qP \\\\############\\ChefEncryptedDatabagKey\\#{@project}\ http://admin:#{contents}@############/artifactory/simple/chef-secrets-local//#{@project}//#{chefDomain}//secret.txt")
#Load the specifc secret file for the decryption
secret = Chef::EncryptedDataBagItem.load_secret("\\\\############\\ChefEncryptedDatabagKey\\#{@project}\\secret.txt")
#Calls the getSourceRest method to get the specific Chef address
getSourceRest
project = @project
#Loads and decrypts the data bag item with the given name.
item = Chef::EncryptedDataBagItem.load(project, "EncryptedItem", secret)
end
def getSourceRest
#Sets the chefClientConfig parameter to hold the directory of the specific knife file
@chefClientConfig = "c://chef//#{@domain}//knife.rb"
f = ::File.open(@chefClientConfig, "r")
while (line = f.gets)
if line.include?("chef_server_url")
@chefServerUrl = line.split(":")[1]
end
end
Chef::Config.from_file(@chefClientConfig)
#Sets the sourcerest parameter to hold the specific Chef address
@sourcerest = Chef::REST.new("http:" + @chefServerUrl + ":4000")
end
@domains = ["DEV","QA","PERF","BETA","LOAD","NL","SB"]
checkArguments
它也来自文件encrypted_data_bag_item.rb。
It is also pulling from the file encrypted_data_bag_item.rb.
ALGORITHM = 'aes-256-cbc'
def [](key)
value = @enc_hash[key]
if key == "id" || value.nil?
value
else
self.class.decrypt(value, @secret)
end
end
def self.decrypt(value, key)
YAML.load(self.decipher(:decrypt, Base64.decode64(value), key))
end
def self.decipher(direction, data, key)
decipher = OpenSSL::Cipher::Cipher.new(ALGORITHM)
decipher.decrypt
decipher.padding = 0
decipher.send(direction)
decipher.pkcs5_keyivgen(key)
ans = decipher.update(data)
ans << decipher.final
ans
end
有人能帮我解决这个问题吗?
Can anyone help me with this problem please?
推荐答案
您键入,或数据和/或字符串的编码。您确定Ruby安装的默认编码是否与数据库的字符集匹配?
http://ruby-doc.org/core-2.2.1/Encoding.html [ ^ ]
Either you key, or the encodings of the data and/or string. Are you sure the default encodings for your Ruby installation match the charset of the database?
http://ruby-doc.org/core-2.2.1/Encoding.html[^]
这篇关于解密返回奇怪的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文