diff options
-rw-r--r-- | rsa.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -48,15 +48,15 @@ namespace RSA{ string exportKey(const Key &key){ string modser=key.mod.serialiseMantissa(); int32_t modlen=modser.size(); - string modlenstr{(char)(modlen&0xff),(char)((modlen>>8)&0xff),(char)((modlen>>16)&0xff),(char)((modlen>>24)&0xff)}; + string modlenstr{(char)((modlen>>24)&0xff),(char)((modlen>>16)&0xff),(char)((modlen>>8)&0xff),(char)(modlen&0xff)}; return Base64::encode(modlenstr + modser + key.exp.serialiseMantissa()); } Key importKey(const string &repr){ string deser=Base64::decode(repr); if(deser.size()<=4)throw invalid_argument("Invalid key string length"); - int modlen=(uint8_t)deser[0]+((uint8_t)deser[1]<<8)+ - ((uint8_t)deser[2]<<16)+((uint8_t)deser[3]<<24); + int modlen=((uint8_t)deser[0]<<24)+((uint8_t)deser[1]<<16)+ + ((uint8_t)deser[2]<<8)+(uint8_t)deser[3]; if((int)deser.size()-4-modlen<=0)throw invalid_argument("Key string incomplete"); Key key; key.mod.deserialiseMantissa(string(deser.begin()+4,deser.begin()+(4+modlen))); |