Suppose the plaintext is a string, and I map the plaintext to the group using setFromHash function before I can perform the encryption operation, and the final decryption is only the hash of the plaintext, not the plaintext, how can I decrypt the plaintext or perform the bilinear operation without mapping the plaintext to the group? (Can this be achieved without using symmetric encryption)
setup(pairingParametersFileName, pkFileName, mskFileName);
keygen(pairingParametersFileName, userAttList, pkFileName, mskFileName, skFileName);
String msg = "dasddwhqoiuhdaiosnioacjijdqwi0jdaposdjiasojcbndusivbuiweshfsaoindoai";
//byte[] sha1Result = sha1(msg);
//Element message = PairingFactory.getPairing(pairingParametersFileName).getGT().newRandomElement().getImmutable();
//Element message = PairingFactory.getPairing(pairingParametersFileName).getGT().newElement().setFromHash(sha1Result, 0, sha1Result.length).getImmutable();
Element message = PairingFactory.getPairing(pairingParametersFileName).getGT().newElement().setFromHash(msg, 0, msg.length).getImmutable();
System.out.println("plaintext:" + msg);
encrypt(pairingParametersFileName, message, accessTree, pkFileName, ctFileName);
Element res = decrypt(pairingParametersFileName, accessTree, ctFileName, skFileName);
System.out.println("decrypt:" + res);
if (message.isEqual(res)) {
System.out.println("successful!");
}
Pairing bp = PairingFactory.getPairing(pairingParametersFileName);
Properties pkProp = loadPropFromFile(pkFileName);
String gString = pkProp.getProperty("g");
Element g = bp.getG1().newElementFromBytes(Base64.getDecoder().decode(gString)).getImmutable();
String g_betaString = pkProp.getProperty("g_beta");
Element g_beta = bp.getG1().newElementFromBytes(Base64.getDecoder().decode(g_betaString)).getImmutable();
String egg_alphaString = pkProp.getProperty("egg_alpha");
Element egg_alpha = bp.getGT().newElementFromBytes(Base64.getDecoder().decode(egg_alphaString)).getImmutable();
Properties ctProp = new Properties();
//compute CT=M *e(g,g)^(alpha s)
Element s = bp.getZr().newRandomElement().getImmutable();
Element CT = message.duplicate().mul(egg_alpha.powZn(s)).getImmutable();
Element C = g_beta.powZn(s).getImmutable();
this is not achievable, pairing-based CP-ABE, if encrypted, requires plaintext in the G_T group, but there is no good way to encode a message to the G_T group
Related
First of all, I found this link which was a HUGE help to get this working.
https://medium.com/#benwmills/using-the-netsuite-suitetalk-api-with-net-core-net-standard-40f1a4464da1
But wanted to post my findings - in case it helps anyone else.
Step 1: Add a Service Reference to your project (WCF Web Service)
Step 2: Create NetSuitePortTypeClient and Open it (use your own account specific)
NetSuitePortTypeClient nsptc = new NetSuitePortTypeClient(NetSuitePortTypeClient.EndpointConfiguration.NetSuitePort, "https://########.suitetalk.api.netsuite.com/services/NetSuitePort_2021_2");
await nsptc.OpenAsync();
Step 3: Create a Transaction Search in this example
TransactionSearch tranSearch = new TransactionSearch();
TransactionSearchBasic tranSearchBasic = new TransactionSearchBasic();
SearchStringField searchstringfield = new SearchStringField();
searchstringfield.#operator = SearchStringFieldOperator.#is;
searchstringfield.operatorSpecified = true;
searchstringfield.searchValue = "$$$$$$";
tranSearchBasic.tranId = searchstringfield;
tranSearch.basic = tranSearchBasic;
Step 4: Call the Search
searchResponse sresponse = await nsptc.searchAsync(CreateTokenPassport(), null, null, null, tranSearch);
AND Here is the CreateTokenPassword function
public TokenPassport CreateTokenPassport()
{
string account = "account";
string consumerKey = "ckey";
string consumerSecret = "csecret";
string tokenId = "token";
string tokenSecret = "tokensecret";
string nonce = ComputeNonce();
long timestamp = ComputeTimestamp();
TokenPassportSignature signature = ComputeSignature(account, consumerKey, consumerSecret, tokenId, tokenSecret, nonce, timestamp);
TokenPassport tokenPassport = new TokenPassport();
tokenPassport.account = account;
tokenPassport.consumerKey = consumerKey;
tokenPassport.token = tokenId;
tokenPassport.nonce = nonce;
tokenPassport.timestamp = timestamp;
tokenPassport.signature = signature;
return tokenPassport;
}
You've left out the ComputeNonce, ComputeTimestamp, ComputeSignature functions so this code doesn't work...
Here is full code from example of calling NetSuite SOAP using C#:
public TokenPassport CreateTokenPassport()
{
string account = DataCollection["login.acct"];
string consumerKey = DataCollection["login.tbaConsumerKey"];
string consumerSecret = DataCollection["login.tbaConsumerSecret"];
string tokenId = DataCollection["login.tbaTokenId"];
string tokenSecret = DataCollection["login.tbaTokenSecret"];
string nonce = ComputeNonce();
long timestamp = ComputeTimestamp();
TokenPassportSignature signature = ComputeSignature(account, consumerKey, consumerSecret, tokenId, tokenSecret, nonce, timestamp);
TokenPassport tokenPassport = new TokenPassport();
tokenPassport.account = account;
tokenPassport.consumerKey = consumerKey;
tokenPassport.token = tokenId;
tokenPassport.nonce = nonce;
tokenPassport.timestamp = timestamp;
tokenPassport.signature = signature;
return tokenPassport;
}
private string ComputeNonce()
{
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
byte[] data = new byte[20];
rng.GetBytes(data);
int value = Math.Abs(BitConverter.ToInt32(data, 0));
return value.ToString();
}
private long ComputeTimestamp()
{
return ((long) (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
}
private TokenPassportSignature ComputeSignature(string compId, string consumerKey, string consumerSecret,
string tokenId, string tokenSecret, string nonce, long timestamp)
{
string baseString = compId + "&" + consumerKey + "&" + tokenId + "&" + nonce + "&" + timestamp;
string key = consumerSecret + "&" + tokenSecret;
string signature = "";
var encoding = new System.Text.ASCIIEncoding();
byte[] keyBytes = encoding.GetBytes(key);
byte[] baseStringBytes = encoding.GetBytes(baseString);
using (var hmacSha1 = new HMACSHA1(keyBytes))
{
byte[] hashBaseString = hmacSha1.ComputeHash(baseStringBytes);
signature = Convert.ToBase64String(hashBaseString);
}
TokenPassportSignature sign = new TokenPassportSignature();
sign.algorithm = "HMAC-SHA1";
sign.Value = signature;
return sign;
}
There is AES encryption function using lua-lockbox lib (https://github.com/somesocks/lua-lockbox)
Lockbox = require("lockbox")
Lockbox.ALLOW_INSECURE = true
String = require("string");
Array = require("lockbox.util.array");
Stream = require("lockbox.util.stream");
ECBMode = require("lockbox.cipher.mode.ecb");
ZeroPadding = require("lockbox.padding.zero");
AES128Cipher = require("lockbox.cipher.aes128");
local aes = ECBMode.Cipher();
aes.setKey(Stream.toArray(Stream.fromString("123456789qwertyu")))
aes.setBlockCipher(AES128Cipher)
aes.setPadding(ZeroPadding);
aes.init()
aes.update(Stream.fromString("lol"))
aes.finish()
k = aes.asHex()
print(k)
How i can decrypt string and get "lol" string?
I'm currently working on an ArangoDB POC. I find that the time taken for document creation is very high in ArangoDB with PyArango. It takes about 5 minutes to insert 300 documents. I've pasted the rough code below, please let me know if there are better ways to speed this up :
with open('abc.csv') as fp:
for line in fp:
dataList = line.split(",")
aaa = dbObj['aaa'].createDocument()
bbb = dbObj['bbb'].createDocument()
ccc = dbObj['ccc'].createEdge()
bbb['bbb'] = dataList[1]
aaa['aaa'] = dataList[0]
aaa._key = dataList[0]
aaa.save()
bbb.save()
ccc.links(aaa,bbb)
ccc['related_to'] = "gfdgf"
ccc['weight'] = 0
ccc.save()
The different collections are created by the below code :
dbObj.createCollection(className='aaa', waitForSync=False)
for your problem with the batch mode in the arango java driver. if you know the key attributes of the vertices you can build the document handle by "collectionName" + "/" + "documentKey".
Example:
arangoDriver.startBatchMode();
for(String line : lines)
{
String[] data = line.split(",");
BaseDocument device = new BaseDocument();
BaseDocument phyAddress = new BaseDocument();
BaseDocument conn = new BaseDocument();
String keyDevice = data[0];
String handleDevice = "DeviceId/" + keyDevice;
device.setDocumentKey(keyDevice);
device.addAttribute("device_id",data[0]);
String keyPhyAddress = data[1];
String handlePhyAddress = "PhysicalLocation/" + keyPhyAddress;
phyAddress.setDocumentKey(keyPhyAddress);
phyAddress.addAttribute("address",data[1]);
final DocumentEntity<BaseDocument> from = arangoDriver.graphCreateVertex("testGraph", "DeviceId", device, null);
final DocumentEntity<BaseDocument> to = arangoDriver.graphCreateVertex("testGraph", "PhysicalLocation", phyAddress, null);
arangoDriver.graphCreateEdge("testGraph", "DeviceId_PhysicalLocation", null, handleDevice, handlePhyAddress, null, null);
}
arangoDriver.executeBatch();
I would build all of the data to be inserted into a json formatted string and use createDocumentRaw to create them all at once with one save.
on the web service side I am applying
StoreRequestParameters parameters = new StoreRequestParameters(this.Context);
string condition= parameters.GridFilters.ToString();
//I ma sending this to the methot "List<Ks> Get(....)"
to get the gridfilter parameters.
inside the other methot ,trying to get the selected gridfilters values like this.
public List<Ks> Get(int start, int limit, string sort, string terssiralama, string condition, out int totalrow)
{
FilterConditions fc = new FilterConditions(condition);
foreach (FilterCondition cnd in fc.Conditions)
{
Comparison comparison = cnd.Comparison;
string fi = cnd.Field;
FilterType type = cnd.Type;
switch (cnd.Type)
{
case FilterType.Date:
switch (comparison)
{
case Comparison.Eq:
field1 = cnd.Field;
cmp1 = "=";
value1 = cnd.Value<string>();
...........
..........
}
but I failed getting the values like this
FilterConditions fc = new FilterConditions(condition);
I couldnt pass the string values .
should I serializes or deserilized first ?
StoreRequestParameters parameters = new StoreRequestParameters(this.Context);
instead of using this, string condition= parameters.GridFilters.ToString();
I use this
string obj = this.Context.Request["filter"];
and pass it to the
FilterConditions fc = new FilterConditions(obj);
It can be reach all filter condition in fc filtercondition variable.
I would like to know what could be the problem in the code below.
I'm part of a university team developing solutions in Bada using NFC and server connections. To encrypt the comunication we have though use Aes encryption, but I'm stopped in the following error:
String
ReadForm::aesEncryp(Osp::Base::String ip, Osp::Base::String mac, Osp::Base::String msg)
{
AppLog("<<<<<<<<<<<<<< aesEncrypt Start >>>>>>>>>>>>>>>>>>>>>>>>>");
Osp::Text::Utf8Encoding utf8Enc;
Osp::Text::AsciiEncoding* dato = new Osp::Text::AsciiEncoding();
result r;
//msg
ByteBuffer* pbuffer=dato->GetBytesN(msg);
AppLog("asigno mensaje: %ls", msg.GetPointer());
int messageLen; // msg.GetLength()*8;
r=dato->GetByteCount(msg,messageLen);
AppLog("obtiene bytes: %s", GetErrorMessage(r));
byte message[messageLen+1];
r=pbuffer->GetArray(message,0,messageLen);
AppLog("Establece mensaje en array: %s", GetErrorMessage(r));
// KEY: 16 bytes
int secretKeyLen;
ip="xxxxxxxxxxxxx";
r=dato->GetByteCount(ip,secretKeyLen);
AppLog("obtiene bytes: %s", GetErrorMessage(r));
pbuffer=null;
pbuffer=dato->GetBytesN(ip);
byte secretKey[secretKeyLen+1];
r=pbuffer->GetArray(secretKey,0,secretKeyLen);
AppLog("Establece key en array: %s", GetErrorMessage(r));
// IV: 16 bytes
int ivectorLen;
String ivM="xxxxxxxxxxxx";
pbuffer=null;
pbuffer=dato->GetBytesN(ivM);
r=dato->GetByteCount(ivM,ivectorLen);
AppLog("obtiene bytes: %s", GetErrorMessage(r));
byte ivector[ivectorLen+1];
r=pbuffer->GetArray(ivector,0,ivectorLen);
AppLog("Establece vector en array: %s", GetErrorMessage(r));
String transformation;
ISymmetricCipher *pCipher = null;
SecretKeyGenerator *pKeyGen = null;
ISecretKey *pKey = null;
ByteBuffer input;
ByteBuffer *pOutput = null;
ByteBuffer keyBytes;
ByteBuffer iv;
//msg
input.Construct(messageLen+1);
input.SetArray(message, 0, messageLen);
input.Flip();
//key
keyBytes.Construct(secretKeyLen+1);
keyBytes.SetArray(secretKey, 0, 16);
keyBytes.Flip();
//vector
iv.Construct(ivectorLen);
iv.SetArray(ivector, 0, ivectorLen);
iv.Flip();
//cifrado
pCipher = new AesCipher();
transformation = "CBC/128/NOPADDING";
pCipher->Construct(transformation,CIPHER_ENCRYPT);
AppLog("AesCipher construct:%s", GetErrorMessage(r));
pKeyGen = new SecretKeyGenerator();
pKeyGen->Construct(keyBytes);
pKey = pKeyGen->GenerateKeyN();
if (pKey==null){
r = GetLastResult();
AppLog("Generate -> pKey Esnulo: %s",GetErrorMessage(r));
}
r=pCipher->SetKey(*pKey);
AppLog("AesCipher setKey:%s", GetErrorMessage(r));
r=pCipher->SetInitialVector(iv);
AppLog("AesCipher setInitialVector:%s", GetErrorMessage(r));
//encripto
pOutput = pCipher->EncryptN(input); <---------- returns null why!!!!!!!!!!!
if (pOutput==null){
r = GetLastResult();
AppLog("pOutput nulo: %s",GetErrorMessage(r));
}
AppLog("Encriptado");
//preparo para devolver
Osp::Text::AsciiEncoding* as = new Osp::Text::AsciiEncoding();
as->GetString(*pOutput,ResultadoAes);
AppLog("aes= %ls", ResultadoAes.GetPointer() );
AppLog("<<<<<<<<<<<<<< aesEncrypt Finish >>>>>>>>>>>>>>>>>>>>>>>>>");
return ResultadoAes;
}
The input and keylength should be multiple of 16.
What i understand from your code, your message length is multiple of 8.
Also since you are using NOPADDING, when you are constructing bytebuffer for input and keybytes, please make sure that they are exactly multiple of 16.
Finally, incase you are still getting problem, please post what error message you are getting from
r = GetLastResult()