Is it possible to convert a member of a class to another member of different class within same cryptosystem in PALISADE? - palisade

Can we convert a member function of one class to that of another?
Using the Palisade library, I wanted to encrypt a private key using another key. However, the 'Encrypt' function in PKE takes variables of class 'Plaintext', and 'LPPublicKey'.
Also, is it possible to interact with elements of different cryptosystems, e.g. use symmetric key encryption of BinFHE to encrypt 'Plaintext' of PKE.

Related

Derive multiple PDAs for one Public Key with a UUID

I am trying to derive multiple PDAs with a generated seed and get the error shown in the screenshot. If i don't use the uuid and only the seed and the public key for the PDA it works fine.
create_planet
planet_struct
rpc_call
error
In your lib.rs in the planet struct the seeds are not in the correct format
it should be like this
seeds=[b"planet",payer.key.as_ref(),&[uuid as u8]]
and in your rpc call file
[anchor.utils.bytes.utf8.encode("planet"),
wallet.publicKey.toBuffer(),
new anchor.BN(80).toArrayLike(Buffer)]

How to maintain variable throughout the application in c#? Multiple users access same variable with different values?

string static str="User1";
Above in str variable we are storing User1 values.but another user store User2 value in same variable .is it possible are not.
Use Singleton class
http://csharpindepth.com/Articles/General/Singleton.aspx
http://www.c-sharpcorner.com/UploadFile/8911c4/singleton-design-pattern-in-C-Sharp/
singleTon classes are C# classes which instences can be only 1 in the application runtime so all you need is to save the str as prop of your singleton class include the class in whichever place you want in application
P.s microsoft link
https://msdn.microsoft.com/en-us/library/ff650316.aspx

Hazelcast mapstore based on map name

I have a Hazelcast instance that organizes data based on map names. The map names are dynamic, so I do not know what they will be until the Hazelcast instance is already started. I now want to store this data in a database via the MapStore functionality, but retain the organization I have setup with the map names. When looking at the MapStore functionality, I do not see any way to retrieve the map or map name that the object came from. Looks like all I get is the key-value pair in the MapStore implementation.
On a broader note, is there any way to get ANY information (not just map name) about the key-value pair needing to be stored? I would like to transfer some knowledge about how to store the data... I know the information when I call map.put(..), but I do not know how to transfer that information to the MapStore call...
I just needed something similar and found that you can implement com.hazelcast.core.MapStoreFactory interface whose 'newMapStore' method gives you the map name and properties from config. From there 'new' your own MapStore implementation passing the map name.
public class MyMapStoreFactory implements MapStoreFactory {
#Override
public MapStore newMapStore(String mapName, Properties properties) {
return new MyMapStoreImplementation(mapName, properties);
}
}
And configure this factory class in hazelcast.xml config like this:
<map name="MapX*">
<map-store enabled="true" initial-mode="EAGER">
<factory-class-name>MyMapStoreFactory</factory-class-name>
</map-store>
</map>
Notice the wildcard on the map name and that <class-name> element must not appear once you set <factory-class-name>.
Tested this with Hazelcast 3.6.1 and it works very fine.
As per my understanding, there is no support out of the box in hazelcast. The following are couple of workarounds I can think of:
Encapsulate the extra information (map name, how to store the data etc) in a context object and store it in a different java map against your key. Use this map in your MapStore implementation later to retrieve respective information which will help you to persist your key,value pairs.
You put operation might look like.
hzMap.put(key, value);
Context context = new Context();
context.setHowToStoreData();
context.setMapName();
// any othe rother information
context.xxx();
// create a unique context key which can be later deduced from (key,value) pair.
contextKey = getUniqueContextKey(key, value);
contextMap.put(contextKey, context);
In your MapStore implementation, you can then make use of this contextMap to retrieve additional values.
Second way would be to encapsulate the information within the (key, value) pair. You can create a new class called CacheEntry to store cache values as well as additional information. You can then later retrieve your cache value as well as additional information from iMap itself.
You put operation might look like.
CacheEntry<YourValueClass> cacheEntry = new CacheEntry<YourValueClass>();
cacheEntry.setValue(value);
cacheEntry.howToStoreData(..);
cacheEntry.setMapName(..);
imap.put(key, cacheEntry);
In your MapStore implementation, you can then make use of the value (which would be a CacheEntry object) itself to retrieve additional information as well as actual value (instance of YourValueClass).

Storing object in Esent persistent dictionary gives: Not supported for SetColumn Parameter error

I am trying to save an Object which implements an Interface say IInterface.
private PersistentDictionary<string, IInterface> Object = new PersistentDictionary<string, IInterface>(Environment.CurrentDirectory + #"\Object");
Since many classes implement the same interface(all of which need to cached), for a generic approach I want to store an Object of type IInterface in the dictionary.
So that anywhere I can pull out that object type cast it as IInterface and use that object's internal implementation of methods etc..
But, as soon as the Esent cache is initialized it throws this error:
Not supported for SetColumn
Parameter name: TColumn
Actual value was IInterface.
I have tried to not use XmlSerializer to do the same but is unable to deserialize an Interface type.Also, [Serializable] attribute cannot be used on top of a Interface, so I am stuck.
I have also tried to make all the implementations(classes) of the Interface as [Serializable] as a dying attempt but to no use.
Does any one know a way out ? Thanks in advance !!!
The only reason that only structs are supported (as well as some basic immutable classes such as string) is that the PersistentDictionary is meant to be a drop-in replacement for Dictionary, SortedDictionary and other similar classes.
Suppose I have the following code:
class MyClass
{
int val;
}
.
.
.
var dict = new Dictionary<int,MyClass>();
var x = new MyClass();
x.val = 1;
dict.Add(0,x);
x.val = 2;
var y = dict[0];
Console.WriteLine(y.val);
The output in this case would be 2. But if I'd used the PersistentDictionary instead of the regular one, the output would be 1. The class was created with value 1, and then changed after it was added to the dictionary. Since a class is a reference type, when we retrieve the item from the dictionary, we will also have the changed data.
Since the PersistentDictionary writes the data to disk, it cannot really handle reference types this way. Serializing it, and writing it to disk is essentially the same as treating the object as a value type (an entire copy is made).
Because it's intended to be used instead of the standard dictionaries, and the fact that it cannot handle reference types with complete transparency, the developers instead opted to support only structs, because structs are value types already.
However, if you're aware of this limitation and promise to be careful not to fall into this trap, you can allow it to serialize classes quite easily. Just download the source code and compile your own version of the EsentCollections library. The only change you need to make to it is to change this line:
if (!(type.IsValueType && type.IsSerializable))
to this:
if (!type.IsSerializable)
This will allow classes to be written to the PersistentDictionary as well, provided that it's Serializable, and its members are Serializable as well. A huge benefit is that it will also allow you to store arrays in there this way. All you have to keep in mind is that it's not a real dictionary, therefore when you write an object to it, it will store a copy of the object. Therefore, updating any of your object's members after adding them to the PersistentDictionary will not update the copy in the dictionary automatically as well, you'd need to remember to update it manually.
PersistentDictionary can only store value-structs and a very limited subset of classes (string, Uri, IPAddress). Take a look at ColumnConverter.cs, at private static bool IsSerializable(Type type) for the full restrictions. You'd be hitting the typeinfo.IsValueType() restriction.
By the way, you can also try posting questions about PersistentDictionary at http://managedesent.codeplex.com/discussions .
-martin

How to auto-generate early bound properties for Entity specific (ie Local) Option Set text values?

After spending a year working with the Microsoft.Xrm.Sdk namespace, I just discovered yesterday the Entity.FormattedValues property contains the text value for Entity specific (ie Local) Option Set texts.
The reason I didn't discover it before, is there is no early bound method of getting the value. i.e. entity.new_myOptionSet is of type OptionSetValue which only contains the int value. You have to call entity.FormattedValues["new_myoptionset"] to get the string text value of the OptionSetValue.
Therefore, I'd like to get the crmsrvcutil to auto-generate a text property for local option sets. i.e. Along with Entity.new_myOptionSet being generated as it currently does, Entity.new_myOptionSetText would be generated as well.
I've looked into the Microsoft.Crm.Services.Utility.ICodeGenerationService, but that looks like it is mostly for specifying what CodeGenerationType something should be...
Is there a way supported way using CrmServiceUtil to add these properties, or am I better off writing a custom app that I can run that can generate these properties as a partial class to the auto-generated ones?
Edit - Example of the code that I would like to be generated
Currently, whenever I need to access the text value of a OptionSetValue, I use this code:
var textValue = OptionSetCache.GetText(service, entity, e => e.New_MyOptionSet);
The option set cache will use the entity.LogicalName, and the property expression to determine the name of the option set that I'm asking for. It will then query the SDK using the RetrieveAttriubteRequest, to get a list of the option set int and text values, which it then caches so it doesn't have to hit CRM again. It then looks up the int value of the New_MyOptionSet of the entity and cross references it with the cached list, to get the text value of the OptionSet.
Instead of doing all of that, I can just do this (assuming that the entity has been retrieved from the server, and not just populated client side):
var textValue = entity.FormattedValues["new_myoptionset"];
but the "new_myoptionset" is no longer early bound. I would like the early bound entity classes that gets generated to also generate an extra "Text" property for OptionSetValue properties that calls the above line, so my entity would have this added to it:
public string New_MyOptionSetText {
return this.GetFormattedAttributeValue("new_myoptionset"); // this is a protected method on the Entity class itself...
}
Could you utilize the CrmServiceUtil extension that will generate enums for your OptionSets and then add your new_myOptionSetText property to a partial class that compares the int value to the enums and returns the enum string
Again, I think specifically for this case, getting CrmSvcUtil.exe to generate the code you want is a great idea, but more generally, you can access the property name via reflection using an approach similar to the accepted answer # workarounds for nameof() operator in C#: typesafe databinding.
var textValue = entity.FormattedValues["new_myoptionset"];
// becomes
var textValue = entity.FormattedValues
[
// renamed the class from Nameof to NameOf
NameOf(Xrm.MyEntity).Property(x => x.new_MyOptionSet).ToLower()
];
The latest version of the CRM Early Bound Generator includes a Fields struct that that contains the field names. This allows accessing the FormattedValues to be as simple as this:
var textValue = entity.FormattedValues[MyEntity.Fields.new_MyOptionSet];
You could create a new property via an interface for the CrmSvcUtil, but that's a lot of work for a fairly simple call, and I don't think it justifies creating additional properties.

Resources