You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let password: [UInt8] = Array("personalKey".utf8)
let salt: [UInt8] = Array("abcdefghijklmnop".utf8)
do {
key = try PKCS5.PBKDF2(password: password, salt: salt, iterations: 100, keyLength: 32, variant: .sha256).calculate()
print("key = \(key)")
}
catch
{
print("generating key error")
}
/* Generate random IV value. IV is public value. Either need to generate, or get it from elsewhere */
let iv: [UInt8] = Array("adcdefghijsobeie".utf8)
// let iv = AES.blockSize.words
/* AES cryptor instance */
do {
sai = try AES(key: key, blockMode: CBC(iv: iv), padding: .pkcs7)
print("aes = \(sai!)")
}
catch
{
print{"aes error"}
}
/* Encrypt Data */
let inputData = "welcome"
do {
var encryptedBytes = try sai.encrypt(inputData.bytes)
print("c = \(inputData.bytes)")
print("b = \(encryptedBytes)")
let encryptedData = Data(encryptedBytes)
print(encryptedData)
var a = salt+iv+encryptedBytes
var result = a.toBase64()
print(a.toBase64())
var g = "yUvSkEge"
final = g+result
print("final = \(final)")
while passing final result i am unable to access the server please let me know i am going wrong
while in java they given code is to encript logic is
Algorithm : AES
Key Size : 256
Key : personalKey
encryptData(msg:any) {
var keySize = 256;
var salt = CryptoJS.lib.WordArray.random(16);
var key = CryptoJS.PBKDF2(Constant.encryptDecryptKey, salt, {
keySize: keySize / 32,
iterations: 100
});
var iv = CryptoJS.lib.WordArray.random(128 / 8);
var encrypted = CryptoJS.AES.encrypt(msg, key, {
iv: iv,
padding: CryptoJS.pad.Pkcs7,
mode: CryptoJS.mode.CBC
});
let generatedKey = this.generateRandomText(parseInt(environment.encryptionKeyLength));
var result = CryptoJS.enc.Base64.stringify(salt.concat(iv).concat(encrypted.ciphertext));
return generatedKey +result;
}
This discussion was converted from issue #902 on July 17, 2022 13:13.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Describe the bug
Reproduce
Steps to reproduce:
// let iv = AES.blockSize.words
while passing final result i am unable to access the server please let me know i am going wrong
while in java they given code is to encript logic is
Algorithm : AES
Key Size : 256
Key : personalKey
encryptData(msg:any) {
var keySize = 256;
var salt = CryptoJS.lib.WordArray.random(16);
var key = CryptoJS.PBKDF2(Constant.encryptDecryptKey, salt, {
keySize: keySize / 32,
iterations: 100
});
Beta Was this translation helpful? Give feedback.
All reactions