Tag: java

Swift将字节数组转换为整数

你好,我是新的swift,并希望将一个字节数组转换为几个整数。 我已经用Java编写了工作代码,但我不太确定如何快速完成工作 byte[] codeData = Base64.decode(codeDataBase64, 0); ByteArrayInputStream bais = new ByteArrayInputStream(codeData); DataInputStream dis = new DataInputStream(bais); byte version = dis.readByte(); if (version == 1) { int anID = dis.readInt(); int anotherID = dis.readInt(); byte[] TK = new byte[512]; int readTK = dis.read(TK); if (readTK == TK.length) { Log.e("photoConnect success", "anID=" + anID + ", […]

使用Java中的身份validation标签进行AES GCM实现

我在我的Android项目中使用AES GCM身份validation,它工作正常。 但是当与openssl API比较时,获得authentication标签的一些问题会生成标签。 请find下面的java代码: SecretKeySpec skeySpec = new SecretKeySpec(key, "AES"); byte[] iv = generateRandomIV(); IvParameterSpec ivspec = new IvParameterSpec(iv); Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec, ivspec); int outputLength = cipher.getOutputSize(data.length); // Prepare output buffer byte[] output = new byte[outputLength]; int outputOffset = cipher.update(data, 0, data.length, output, 0);// Produce cipher text outputOffset += cipher.doFinal(output, outputOffset); […]

Codename一个GPS提供者和当前位置

我正在使用代号为1的iOS应用程序。 我想获得当前位置并通过短信发送。 我从Java Android Studio获得了这个代码,我不知道如何获取当前位置,并检查GPS是否打开。 我在下面尝试,但没有成功(我不知道他们如何启动GPS,并获得位置) LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); boolean enabledGPS = service.isProviderEnabled(LocationManager.GPS_PROVIDER); if (!enabledGPS) { //alert GPS is off } LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Define the criteria how to select the location provider -> use // default Criteria criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, false); Location location = locationManager.getLastKnownLocation(provider); […]

有没有办法让一个Android软键盘只有数字(没有小数点,空格)与Java代码?

我有一个使用不同键盘布局的iPhone应用程序。 有些是自定义的,有些是内置的: 仅数字: 小数点: ISBN号码的自定义Xbutton: 我想在Android上做同样的事情,但即使是正常的InputType.TYPE_CLASS_NUMBER仍然包含小数点,空格,逗号等。 我怎样才能在Android中自定义键盘?

AESencryptionAndroid < – > iOS消息长度大于15字节的不同结果

在理解这两个设备上的密码/解密器时,我遇到了一个真正的问题。 1.如果我们使用Cipher AES在iOS和Android上对消息进行encryption,并且string的字符长度不大于16(例如“abcdefghijklmno”),则使用相同的密钥/密码进行encryption后得到相同的结果。 2.但是,如果采取更长的消息,我们会在iOS和Android上获得不同的结果(例如“abcdefghijklmnop”) 我做了很多研究,如何得到这两个设备相同的参数,起初我认为这是安全的。 这是我的encryption密码: public String encode(Context context, String password, String text) throws NoPassGivenException, NoTextGivenException { if (password.length() == 0 || password == null) { throw new NoPassGivenException("Please give Password"); } if (text.length() == 0 || text == null) { throw new NoTextGivenException("Please give text"); } try { SecretKeySpec skeySpec = getKey(password); byte[] […]

将数据从iOS发送到Java套接字服务器并识别该消息

我不明白这一点,我在我的应用程序中做这个代码,并在服务器端不认识这个消息为什么? NSString *init = @"?II#$%_0"; NSData *myData = [init dataUsingEncoding:NSUTF16BigEndianStringEncoding]; uint8_t *readBytes = (uint8_t *)[myData bytes]; int size = [myData length]; int myInteger = CFSwapInt16HostToBig(size); NSInteger nwritten = [outputStream write:readBytes maxLength:myInteger]; 而在远程服务器的另一端识别消息,但不是这样的。 0I0I0#0$0%0_0O0000000000000000#0000000000000000 这是从string消息的II#$ _ 0我发送但000000和这个000不是cero是一个正方形,但我不知道如何写这个字符。 接下来的错误 java.io.UTFDataFormatException: malformed input around byte 27 at java.io.DataInputStream.readUTF(DataInputStream.java:639) at java.io.DataInputStream.readUTF(DataInputStream.java:547) 我不明白 请大家抱歉,因为我的英文很糟糕。 :/

如何提高室内定位使用云台信标设备的数据稳定性和准确性?

在android中如何提高multipe信标检测的稳定性?我使用的是Gimbal信标进行室内定位,BLE是否适用于室内位置数据访问?

更改react-native项目中android和ios的入口文件path

使用react-native init awesomeProject启动一个新项目后,我尝试重新构build项目,将index.ios.js和index.android.ios放入一个名为src的公用文件夹中。 当我执行react-native run-android时 ,出现以下错误: 在Android设备上的错误 在哪里我必须改变,以正确的path反应原生search条目文件?

转换Java到iOS

有没有可用于将Android的Java代码转换为iOS的库? 如果不止一个请列举优点。

将PEM公钥读入iOS

我有一个由java使用这个代码生成的base64公钥: RSAPublicKeySpec rsaKS = new RSAPublicKeySpec(modulus, pubExponent); RSAPublicKey rsaPubKey = (RSAPublicKey) kf.generatePublic(rsaKS); byte[] encoded = rsaPubKey.getEncoded(); String base64 = Base64.encodeToString(encoded, Base64.DEFAULT); Log.e(null, "base64: " + base64); 这导致Base64string。 在OSX中,我可以使用这个代码得到一个SecKeyRef: // Create the SecKeyRef using the key data CFErrorRef error = NULL; CFMutableDictionaryRef parameters = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, NULL); CFDictionarySetValue(parameters, kSecAttrKeyType, kSecAttrKeyTypeRSA); CFDictionarySetValue(parameters, kSecAttrKeyClass, kSecAttrKeyClassPublic); SecKeyRef keyRef […]